I’m working on an application where dates are passed as yyyy-mm-dd but displayed to the client as mm-dd-yyyy (US based client).
I’m using a jQuery datepicker for selecting from/to dates in a report and would like to show the dates to the client as mm-dd-yyyy but when the form is submitted, submit as yyyy-mm-dd.
Is it possible to display one value in a textinput textbox and have another submitted without needing to hook into onSubmit?
I’ve come up with the following alternatives:
-
Hide the text input for the from and to fields, create dummy fields and make use of the following jQuery date picker functions: altField and altFormat to display the value to the client in their preferred way and deal only with the submitted values which are set through the alt functions.
-
Have an onSubmit javascript call to change the dates from mm-dd-yyyy to dd-mm-yyyy and also change the value=” to change the date to the client’s preferred format.
-
Rewrite the app to handle all dates in mm-dd-yyyy and hope the client never has non-US customers that would like their dates in a specific format.
-
Change all dates to dd-Mon-YYYY e.g. 26-May-2010 as all of our client’s customers are guaranteed to be English only.
The way I do this is to translate before display and after submit in my PHP code. I am getting dates from a MySQL database which are in the ‘YYYY-MM-DD’ format, but displaying them in the form with a jQuery UI datepicker in the ‘MM/DD/YYYY’ format.