2

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.

Allan Pereira
  • 2,572
  • 4
  • 21
  • 28
Prashanth v
  • 202
  • 3
  • 15
  • 1
    Dont store dates as strings, store them as date type. – musefan Jun 01 '18 at 09:55
  • If you want to add code to your question then edit it – musefan Jun 01 '18 at 09:59
  • 1
    Possible duplicate of [Change jquery date picker format](https://stackoverflow.com/questions/21334915/change-jquery-date-picker-format) – VijayD Jun 01 '18 at 10:02
  • 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 Jun 01 '18 at 10:18
  • https://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 Jun 01 '18 at 10:57

1 Answers1

0

Please try this to get the value

 $("#mydate").datepicker("option", "dateFormat", "yyyy-mm-dd" ).val();
Madhu Nair
  • 428
  • 1
  • 7
  • 20
  • https://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 Jun 01 '18 at 10:57
  • you need to add date picker js and css – Madhu Nair Jun 01 '18 at 11:25
  • its working now ..please check https://jsfiddle.net/prashanthviru/b42dzwLb/ – Madhu Nair Jun 01 '18 at 11:33
  • alert must be in yyy-mm-dd format check fiddle it alert in dd-mm-yyyy format only – Prashanth v Jun 01 '18 at 11:34
  • please check now @Prashanthv its done https://jsfiddle.net/prashanthviru/b42dzwLb/ – Madhu Nair Jun 01 '18 at 12:09
  • no its not working plz check it again alert in dd-mm-yyyy i need alert in yyyy-mm-dd format @madhu Nair – Prashanth v Jun 01 '18 at 12:23
  • `code function GetFormattedDate(mydate) { var fields = mydate.split('-'); var day = fields[0]; var month = fields[1]; var year = fields[2]; abc= year +-+month+-+day; return abc }` place this and pass the value the result is your desired one – Madhu Nair Jun 01 '18 at 12:24
  • thanks @madhu one more problem i have multiple form in site so iam calling same datepicker so i need to know that multiple script must be include ? r can use common script to all forms and iam also submiting form in ajax submit and serialize data so how to do with this – Prashanth v Jun 01 '18 at 12:33