2
votes

I am using jQuery datepicker, and I am displaying my date in

dd-mm-yyyy

format but I need to send date in

yyyy-mm-dd

format to store in database.

$(document).ready(function(){
    $('.datepicker').datepicker({
        format : 'dd-mm-yyyy',
        maxDate : new Date(),
        selectMonths : true,
        selectYears: d,
        yearRange: 100 ,
    }); 
});

the above code will show date format

dd-mm-yy

and when I submit the form using ajax, it sends using this same format. I need to change the submit format to

yyyy-mm-dd

Check this fiddle.

1
Dont store dates as strings, store them as date type. - musefan
If you want to add code to your question then edit it - musefan
Possible duplicate of Change jquery date picker format - VijayD
If your database is storing dates in a column of type string, rather than of type date, then you will save yourself a lot of pain if you just migrate the column to the date type. However, we realise this might not be possible, if someone else in in charge of the database schema, if the system is already in place, or if the DB is accessed through a stringly-typed protocol. (@musefan) - user234461
jsfiddle.net/prashanthviru/b42dzwLb check this fiddle in alert my idea is to alert in yyyy-mm-dd format so fiddle me code - Prashanth v

1 Answers

0
votes

Please try this to get the value

 $("#mydate").datepicker("option", "dateFormat", "yyyy-mm-dd" ).val();