Topic: Changing date format from form to database
This is an input tag from a simple form to show a proposed future delivery date:-
<input id="date" type='text' name='date10' value='<?php echo date("d F Y", strtotime('+10 days'));?>' size='30'>
which shows in the form input box as 12 November 2009 (+10 days from current date) and is in the format I want to display.
When submitted to the MySQL database the date is rejected because the database can only accept a date in a format of y-m-d or y/m/d.
How can I change the format inside the input tag so that the date is sent to the database in a different format but still keep the form in the format I want?
I can code the input tag in the correct format for the database but then the display is not in the format I want.
It seems that the value="..." in the form input tag serves two purposes, to display the value in the form and to send the value to the database, so if I format for the display it sends the wrong format to the database; if I try to put two values in the input tag it objects or sends the wrong one to the database. I have thought of having a dummy input tag with display: hidden but can't get it to work yet.
Additionally, if the format is y-m-d (which works but I don't want) the viewer can change the date if he doesn't like it and the revised date will go to the database, and I'd like this to happen with my desired format. I may have to put the date outside the form, but then how do I get it into the database?
Last edited by Wickham (2009-11-03 02:12:44)
