I am trying to set the jquery datepicker date format but it is not working, I have read few posts and answer already but none of them worked for me. Below is the code I am using please check and tell me where I am doing wrong. I am getting the datetime from Database as 2012-03-06 00:00:00 UTC
<script>
$(document).ready(function() {
$(".datepicker").datepicker({
dateFormat:'MM-DD-YYYY'
}).val();
});
</script>
Also I tried
<script>
$(document).ready(function() {
var dateTypeVar = $('.datepicker').datepicker('getDate');
$.datepicker.formatDate('dd-mm-yy', dateTypeVar);
});
</script>
Do one of the following: For a text box control or a date picker control, ensure that the Data type list displays the appropriate data type, and then click Format. For an expression box control, ensure that the Format as list displays the appropriate data type, and then click Format.
Re: convert Date from YYYY-MM-DD to MM/DD/YYYY in jQuery/JavaScript. var tempDate = new Date("2021-09-21"); var formattedDate = [tempDate. getMonth() + 1, tempDate.
inside the jQuery script code just paste the code. $( ". selector" ). datepicker({ dateFormat: 'yy-mm-dd' });
This 2012-03-06 00:00:00 UTC
is not a valid JavaScript date, so the datepicker
can't accept the value assigned.
Date
object: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date
setDate
method: http://api.jqueryui.com/datepicker/#method-setDate
Get the date in a compliant format, and then set the datepicker
in this way.
Code:
$(document).ready(function () {
var dbDate = "2012-03-06";
var date2 = new Date(dbDate);
$(".datepicker").datepicker({
dateFormat: 'mm-dd-yy'
}).datepicker('setDate', date2)
});
Demo: http://jsfiddle.net/IrvinDominin/7ck7D/
$(document).ready(function () {
var date2 = new Date().getDate()-9;
$(".datepicker").datepicker({
dateFormat: 'dd-mm-yy'
}).datepicker('setDate', date2)
});
http://jsfiddle.net/IrvinDominin/7ck7D/
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