Lucky1000 Posted November 3, 2011 Share Posted November 3, 2011 Hi I am new to PHP and trying to convert a date from a registration form (in the form 01/01/2011) to Y-m-d so that it can be stored in the database. This is the code I have, pretty sure it worked before but not it has stopped working! Any ideas? $dateformat = $_POST['dob']; $correctformat = date('Y-m-d',strtotime($dateformat)); I have checked what $_POST['dob'] is printing and that is correct, however the $correctformat is printing 1970-01-01 everytime. Any help would be greatly apreciated. Thank you Link to comment https://forums.phpfreaks.com/topic/250369-strtotime-not-working/ Share on other sites More sharing options...
salathe Posted November 3, 2011 Share Posted November 3, 2011 What format is the date? strtotime() will accept m/d/Y but not d/m/Y. Link to comment https://forums.phpfreaks.com/topic/250369-strtotime-not-working/#findComment-1284601 Share on other sites More sharing options...
Lucky1000 Posted November 3, 2011 Author Share Posted November 3, 2011 the date format from the form is - d/m/Y e.g. 01/01/2011 Link to comment https://forums.phpfreaks.com/topic/250369-strtotime-not-working/#findComment-1284605 Share on other sites More sharing options...
AbraCadaver Posted November 3, 2011 Share Posted November 3, 2011 Then it needs to be d-m-Y: $correctformat = date('Y-m-d', strtotime(str_replace('/', '-', $dateformat))); Link to comment https://forums.phpfreaks.com/topic/250369-strtotime-not-working/#findComment-1284671 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.