Reputation: 2367
I have this code currently:
$('#cal').datepicker({
onSelect: function(dateText, inst) {
var dateAsString = dateText; //the first parameter of this function
var dateAsObject = $(this).datepicker( 'getDate' ); //the getDate method
}
});
I wanted to know how I can call parseDate on dateAsObject to format it as such: YYYY/MM/DD. To store into mysql DATE field
Upvotes: 0
Views: 2353
Reputation: 9661
you can add this :
dateFormat: '{dateFormat}'
$('#cal').datepicker({
dateFormat: 'YYYY/MM/DD',
onSelect: function(dateText, inst) {
var dateAsString = dateText; //the first parameter of this function
}
});
Upvotes: 1
Reputation: 69915
There is no direct date formatter in JavaScript
. You can either use any jQuery plugin to format the date as per your required format or you can just use this code to get the date formatted as per your requirement.
dateAsObject.getFullYear()+"/"+(dateAsObject.getMonth()+1)+"/"+ dateAsObject.getDate()
Upvotes: 0