im using this datetimepicker http://eonasdan.github.io/bootstrap-datetimepicker/ in my edit form. Im not able to set up default value in this datetimepicker from my variable date. If I use $('#edit_cost_date').val(json[0]['date']);
on input element, the value in input is right but if i open datetimepicker i see that marked is not the date in input but actual date.
var date = json[0]['date'];
$(function () {
$('#datetimepicker-edit-cost').datetimepicker({
locale: 'cs',
format:'DD.MM.YYYY'
});
});
Go to line 1399 and find format: 'mm/dd/yyyy' . Now you can change the date format here.
Syntax: $(". selector"). datepicker( {defaultDate:"+6"} );
In order to set the date format, we only need to add format of one argument and then we will add our required format, which is shown in the following example: Example 1: In this example, we are going to use dd-mm-yyyy format.
Are you sure your date
variable is a Date object? If it is not, you will need to set the default date like this:
var date = json[0]['date'];
$(function () {
$('#datetimepicker-edit-cost').datetimepicker({
locale: 'cs',
format:'DD.MM.YYYY',
defaultDate: new Date(date)
});
});
More information about the date
property for that plugin:
http://eonasdan.github.io/bootstrap-datetimepicker/Functions/#date
date([newDate])
Takes newDate string, Date, moment, null parameter and sets the components model current moment to it. Passing a null value unsets the components model current moment. Parsing of the newDate parameter is made using moment library with the options.format and options.useStrict components configuration.
Throws
TypeError - in case the newDate cannot be parsed
Emits
change.dp - In case newDate is different from current moment
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With