Page 1 of 1

recording date from input field

Posted: Fri Jul 20, 2007 10:41 am
by aceconcepts
Hi,

I'm have some difficulty recording a date into a database from a fomr text field.

I have a form that contains a field named 'sDate'.

This form is submitted to 'page2' and then re-formatted to suit the date mask "0000-00-00"

i.e.

Code: Select all

$sDate = date("Y-m-d", strtotime($_POST['sDate'])); //THIS IS THE VALUE THAT WILL BE RECORDED IN DB
The date is input like this: dd/mm/yyyy

It is recorded into the db like this: yyyy-mm-dd

My problem is that it keeps going wrong!!!

e.g. I entered the date "25/04/1982" and it was recorded like this: "1984-01-04"

Any ideas?

Posted: Fri Jul 20, 2007 11:44 am
by Ambush Commander
strtotime is parsing the input as if it were mm/dd/yyyy, the US format. You'll need to manually parse the string.