简体   繁体   English

引导 daterangepicker 选择开始日期 + 30 天作为 maxDate

[英]Bootstrap daterangepicker selected start date + 30 days as maxDate

I was wondering if someone could help me.我想知道是否有人可以帮助我。 Using the Dan Grossman's Bootstrap Date Picker I want to add 30 days onto the selected start date and define that as the maxDate so a user can't select past this date.使用 Dan Grossman 的 Bootstrap 日期选择器,我想在选定的开始日期上添加 30 天,并将其定义为 maxDate,这样用户就不能选择超过此日期。

I'm really stuck on this and I can't find any docummentation relating to what I want to do.我真的坚持这一点,我找不到任何与我想做的事情有关的文件。 Here is my code;这是我的代码;

var min_date = new Date();
var max_date = '05/31/2013';

$('#limited').daterangepicker(
{
    minDate: min_date,
    maxDate: max_date,
},
function(start, end) {
    $('#limited')
        .data("showAddEventDialogue_dateRangeStart", start)
        .data("showAddEventDialogue_dateRangeEnd", end);
});

Any help or advice would be very much appreciated.任何帮助或建议将不胜感激。

Thanks a million.太感谢了。

It seems that the plugin only accepts a specific date format for minDate and maxDate , which is mm/dd/yyyy . 看来这个插件只接受minDatemaxDate的特定日期格式,即mm/dd/yyyy

Just using new Date(); 只需使用new Date(); unfortunately doesn't work, as it returns the full date, which is incorrect in format. 不幸的是,它不起作用,因为它返回完整的日期,格式不正确。

The code below seems to work for me, it will use always use today as min and +30 as max. 下面的代码似乎对我有用,它将始终使用今天作为min和+30作为最大值。

/* Get the code into mm/dd/yyyy format */
function getFormatDate(d){
    return d.getMonth()+1 + '/' + d.getDate() + '/' + d.getFullYear()
}

$(document).ready(function() {
    var minDate = getFormatDate(new Date()),
    mdTemp = new Date(),
    maxDate = getFormatDate(new Date(mdTemp.setDate(mdTemp.getDate() + 30)));

    $('#daterange').daterangepicker(
    {
       minDate: minDate,
       maxDate: maxDate
    }
    );
});

As thebrieflabb has mentioned in his comment you can solve this problem as follows: 正如thebrieflabb在他的评论中提到的,你可以解决这个问题如下:

var endDate = new Date();
endDate.setDate(startDate .getDate()+30);

You can find more your solution in this thread . 您可以在此主题中找到更多解决方案。

Hope this helped. 希望这有帮助。

Date = new Date(),
maxDate = new Date(Date.setDate(Date.getDate() + 30)),
$('#daterange').daterangepicker({
    minDate: new Date(), 
    maxDate: maxDate ,
    locale: {
       format: 'DD-MM-YYYY',
       firstDay: 1
    },
});

You can use like this: 你可以像这样使用:

var date2 = new Date();
date2.setDate(date2.getDate()-1);
console.log(date2);
$('#daterange').daterangepicker({
    showDropdowns: false,
    format:'MM/DD/YYYY',
    maxDate:date2,
    autoclose: true,
    autoApply:true,

});

Hope it will help anyone. 希望它会帮助任何人。

You need set maxDate and minDate like below : you should store in variable then use it. 您需要设置maxDate和minDate,如下所示:您应该存储在变量中然后使用它。

var prev_date = new Date();
prev_date.setDate(prev_date.getDate() - 1);

$('input[name="daterange"]').daterangepicker({
        opens: 'left',
        showDropdowns: true,
        autoUpdateInput: false,
        maxDate: prev_date,
        locale: {
            cancelLabel: 'Clear',
            format: 'MMM DD, YYYY'
        }
    });

and if u want to allow user to select prev dates only 如果你想让用户只选择上一个日期
ex. 恩。 Date of birth u can use this prop. 出生日期你可以使用这个道具。
startDate : prev_date

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM