recording date from input field

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
aceconcepts
DevNet Resident
Posts: 1424
Joined: Mon Feb 06, 2006 11:26 am
Location: London

recording date from input field

Post 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?
User avatar
Ambush Commander
DevNet Master
Posts: 3698
Joined: Mon Oct 25, 2004 9:29 pm
Location: New Jersey, US

Post 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.
Post Reply