[英]How to fix custom date range issue in daterangepicker?
if($selected_date_interval == 'Yesterday'){
$_SESSION['start_date_by_interval'] = "moment().subtract(1, 'days')";
$_SESSION['end_date_by_interval'] = "moment().subtract(1, 'days')";
}
elseif ($selected_date_interval == 'Today'){
$_SESSION['start_date_by_interval'] = "moment()";
$_SESSION['end_date_by_interval'] = "moment()";
}
elseif($selected_date_interval == 'Last 7 Days'){
$_SESSION['start_date_by_interval'] = "moment().subtract(6, 'days')";
$_SESSION['end_date_by_interval'] = "moment()";
}
elseif ($selected_date_interval == 'Last 30 Days')
{
$_SESSION['start_date_by_interval'] = "moment().subtract(30, 'days')";
$_SESSION['end_date_by_interval'] = "moment()";
}
elseif ($selected_date_interval == 'This Month'){
$_SESSION['start_date_by_interval'] = "moment().startOf('month')";
$_SESSION['end_date_by_interval'] = "moment().endOf('month')";
}
elseif ($selected_date_interval == 'Last Month'){
$_SESSION['start_date_by_interval'] = "moment().subtract(1, 'month').startOf('month')";
$_SESSION['end_date_by_interval'] = "moment().subtract(1, 'month').endOf('month')";
}else{
$_SESSION['start_date_by_interval'] = "moment($start_date,'MMMM D, YYYY')";
$_SESSION['end_date_by_interval'] = "moment($end_date,'MMMM D, YYYY')";
}
All type of my date ranges is working well instead of custom date.我的所有类型的日期范围都运行良好,而不是自定义日期。 Whenever I select a custom date then the date is showing not correct.
每当我选择自定义日期时,日期显示不正确。 So for the custom date, I am passing the date type and format above in last else condition.
所以对于自定义日期,我在最后一个 else 条件中传递了上面的日期类型和格式。 What I am doing wrong please tell me.
我做错了什么请告诉我。
Note- I am using http://daterangepicker.com library.注意 - 我正在使用http://daterangepicker.com库。
This is my datepicker javascript code.这是我的日期选择器 javascript 代码。
$('#reportrange').daterangepicker({
"showDropdowns": true,
"autoApply": false,
ranges: {
'Today': [moment(), moment()],
'Yesterday': [moment().subtract(1, 'days'), moment().subtract(1, 'days')],
'Last 7 Days': [moment().subtract(6, 'days'), moment()],
'Last 30 Days': [moment().subtract(30, 'days'), moment()],
'This Month': [moment().startOf('month'), moment().endOf('month')],
'Last Month': [moment().subtract(1, 'month').startOf('month'), moment().subtract(1, 'month').endOf('month')],
// 'Custom': [moment(end,'YYYY-MM-DD'), moment(start,'YYYY-MM-DD')]
// 'Custom Range': [end, start]
},
startDate: start,
endDate: end,
"locale": {
"format": "YYYY-MM-DD",
"separator": "-",
"applyLabel": "Apply",
"cancelLabel": "Cancel",
"fromLabel": "From",
"toLabel": "To",
"customRangeLabel": "Custom",
"weekLabel": "W",
"daysOfWeek": [
"Su",
"Mo",
"Tu",
"We",
"Th",
"Fr",
"Sa"
],
"monthNames": [
"January",
"February",
"March",
"April",
"May",
"June",
"July",
"August",
"September",
"October",
"November",
"December"
],
"firstDay": 1
},
opens: 'left'
}, cb);
cb(start, end);
});
I am not sure if you got it working or not but I was also searching for solution of same issue and got fix for this.我不确定你是否让它工作,但我也在寻找同样问题的解决方案并解决了这个问题。
Solution is as follows:解决方法如下:
In your code you are defining : 'Custom Range': [end, start]
instead of this you have to provide your start and end date in [moment().subtract(30, 'days'), moment()]
format.在您的代码中,您要定义:
'Custom Range': [end, start]
而不是这个,您必须以[moment().subtract(30, 'days'), moment()]
格式提供开始和结束日期。 So u will have to find difference of days and provide it in place of 'moment().subtract(30, 'days')'
.所以你必须找到天数的差异并提供它来代替
'moment().subtract(30, 'days')'
。 For me this solution works fine.对我来说,这个解决方案工作正常。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.