I have to disable past dates in Eonasdan bootstrap datetimepicker v4,
My Code is :
$('input#startDate,input#endDate').datetimepicker({
format: 'DD/MM/YYYY hh:mm:ss',
startDate: new Date()
});
$('#datetimepicker').datetimepicker({
minDate:new Date()
});
Related
I have a DataTable with a column for date and time with momentjs format 'lll', the date range filter is not working.
{
column_number : 4,
filter_type: 'range_date',
date_format: 'M d, yyyy',
}
You can try using bootstrap date picker, with the following setup (requires https://github.com/Eonasdan/bootstrap-datetimepicker files)
{
column_number : 4,
filter_type: 'range_date',
datepicker_type: 'bootstrap-datetimepicker',
moment_date_format: 'M d, yyyy',
datepicker_type: 'bootstrap-datetimepicker'
}
I've seen answers that use either, new Date() or moment() to declare minDate and been marked as the answer but in my case neither worked.
E.g. How to disable past dates from today in bootstrap datetimepicker?
The code is:
$('.datePicker').datetimepicker({
//format: "HH:ii P, dd M yyyy",
//format: 'YYYY-MM-DD',
//minDate: new Date(),
//minDate: moment(),
minuteStep: 1,
showMeridian: true,
todayBtn: true
});
Bootstrap v3.3.7 is being used and it looks like:
As you can see the dates prior to the 16th (today) aren't being disabled. Could this be due to my bootstrap version?
minDate is for eonasdan-datetimepicker, while tarruda's datetimepicker uses startDate:
Options
These are the default options for initializing the widget:
$.fn.datetimepicker.defaults = {
startDate: -Infinity, // set a minimum date
endDate: Infinity // set a maximum date
};
So I'm using datatables and their moment.js plugin (https://datatables.net/plug-ins/dataRender/datetime). I always get (the string) "Invalid date" returned...
{ "data": "last_updated", //source: 2016-11-02 10:32pm GMT
render: $.fn.dataTable.render.moment( 'YY-MM-DD hh:mmtt GMT', 'DD MMM YY' )
}
Thanks!
That plugin takes one, two or three arguments. From testing it seems as though your date is valid so I'd suggest just passing "SS MMM YY" to the function. As a quick example this seems to work:
moment("2016-11-02 10:32pm GMT").format("DD MMM YY"); // "02 Nov 16"
Another issue might be that the date isn't set, so it's perhaps worth checking for nulls and setting some default content. In fact, if you've already got momentjs available you can replace the plugin with this as the render function:
"render": function(data){
return (moment(data).isValid()) ? moment(data).format("DD MMM YY") : "-";
}
Hope that helps.
I am using a datepicker in titanium iOS to read date.
When I am trying to set a value to the date picker t wont work.It is always showing the maxDate.
What is the actual solution for this
//my sample code of picker is follows
var picker2 = Ti.UI.createPicker({
type: Ti.UI.PICKER_TYPE_DATE,
selectionIndicator: true,
minDate: new Date(moment().subtract(120, 'years')),
maxDate: new Date(moment().subtract(18, 'years')),
value: new Date(2014,3,12),
//value: navHistory == 'profilePage' && dateofbirth !=null ? dateofbirth : new Date(moment().subtract(18, 'years')),
top: Ti.Platform.displayCaps.platformHeight / 30,
});
The reason your current solution does not work is because your value is actually a date after your maxDate (hence it will set the value to maxDate). You need to use a date within minDate and maxDate as value for it to work.
For example:
var picker = Ti.UI.createPicker({
type: Ti.UI.PICKER_TYPE_DATE,
selectionIndicator: true,
minDate: new Date(moment().subtract(120, 'years')),
maxDate: new Date(moment().subtract(18, 'years')),
value: new Date(1990,3,12)
});
I have the following date picker
{
xtype: 'datefield',
id: 'FinalDespatchDate',
name: 'FinalDespatchDate',
fieldLabel: 'Part Despatch Date',
labelWidth: 150,
width: 370,
validateOnChange: false,
format: 'd/m/Y'
},
In my model i have
{
mapping:'FinalDespatchDate',
name:'FinalDespatchDate',
type: 'date',
dateFormat:'d/m/Y'
},
if in my model i don't include the dateFormat. The date binds to my date picker but it sends the date in an incorrect format. When i add dateFormat it sends the date in the correct format it just no longer binds to the datepicker. ie the above configuration display nothing in the date picker
Does your data come from server with properly formatted date value ('d/m/Y') in this (non-working) configuration?