Reputation: 913
I have a bootstrap datepicker I use that has this formatting:
$('#dp2').datepicker({
format: "MM,d,yyyy - DD",
orientation: "top",
todayHighlight: true,
autoclose: true
});
This will output a friendly readable date like this:
July,26,2017 - Wednesday
however when I submit my form I want the date to be formatted in a date like this so it can play nice with the mysql database:
07/26/2017
What can I do to reformat the date to what I need upon a form submit ( i got the form submit working just need to know how to reformat the date upon form submit)
I am using Bootstrap's datepicker.
Thank you in advanced!
Upvotes: 0
Views: 692
Reputation: 1927
Try formatting the date object like this:
var date = $('#dp2').datepicker('getDate');
var formattedDate = $.datepicker.formatDate('mm/dd/yy', date);
Update: With bootstrap's datepicker use:
var date = $('#dp2').datepicker('getDate');
var month = date.getMonth() + 1;
var day = date.getDate();
var year = date.getFullYear();
var formattedDate = month + '/' + day + '/' + year;
Upvotes: 2