1

I have a DatePicker field, I would like it to show this format : 'M d', but I want the value of this date in this date format 'yy-mm-dd'.

Is there a way to show a date format and submitted another one ?

Here my DatePicker fonction

    $( "#datepicker" ).datepicker({
                dateFormat: \'yy-mm-dd\',   
                buttonImage: \'calendar.png\',   
                buttonImageOnly: true,   
                showOn: \'button\',   
   });

Here my field

<input type="text" name="simulateur[startingDate]" id="datepicker" required>
colinec
  • 31
  • 6
  • 2
    possible duplicate of [jQuery UI DatePicker - Change Date Format](http://stackoverflow.com/questions/1328025/jquery-ui-datepicker-change-date-format) – Mivaweb Dec 11 '14 at 09:53

2 Answers2

0

You can try it using altField/AltFormat options:

http://api.jqueryui.com/datepicker/#option-altField http://api.jqueryui.com/datepicker/#option-altFormat

kurroman
  • 978
  • 10
  • 12
0

You can achieve this using altFormat and altField properties of datepicker.

Suppose you are having two inputs, one is for displaying your required date and other for holding date value of format as "yy-mm-dd"

<input type="text" name="begin-date" id="begin-date" value="" />
<input type="text" id="alt-date" />

Apply js as:

$("#begin-date").datepicker({   
  dateFormat: "M d",
  altFormat: "yy-mm-dd",
  altField: "#alt-date"
});

Then first input will show date in "M d" format and second one show in "yy-mm-dd" format, as per your requirements :)

Please refer to fiddle for same.

Mazzu
  • 2,799
  • 20
  • 30
  • Thats perfect. Actually, is it possible to divide the date "M d" to show it in two different input ? Like one input with the month, and one input with the day ? Like that I can stylize the month and the day differently. – colinec Dec 11 '14 at 15:54