glenelkins Posted June 18, 2006 Share Posted June 18, 2006 ok so i have written a little test script as im having problems with inserting dates into a date field in the MySql db. It always seems to put any date into the db as: 0000-00-00 or something wierd like 2017-12-05 or 1970-12-05 etchere is the small test code (line by line to see what is happening)[code]$inputdate = "2006-06-18";echo "INPUT DATE: " . $inputdate . "<br>"; $exploded = explode("-",$inputdate); echo "DAY: " . $exploded[2] . " MONTH: " . $exploded[1] . " YEAR: " . $exploded[0] . "<br>"; $date = date("d-m-Y", mktime(0,0,0,0,$exploded[1],$exploded[2],$exploded[0])); echo "DATABASE DATE: " . $date . "<BR>";[/code]I get this output:INPUT DATE: 2006-06-18DAY: 18 MONTH: 06 YEAR: 2006DATABASE DATE: 05-12-2017This is so annoying after writing a big website and this one little thing is not working. Any ideas people? Quote Link to comment https://forums.phpfreaks.com/topic/12296-most-annoying-problem-with-dates/ Share on other sites More sharing options...
AndyB Posted June 18, 2006 Share Posted June 18, 2006 Try:[code]$date = date("d-m-Y", mktime(0,0,0,$exploded[1],$exploded[2],$exploded[0]));[/code] Quote Link to comment https://forums.phpfreaks.com/topic/12296-most-annoying-problem-with-dates/#findComment-46970 Share on other sites More sharing options...
poirot Posted June 18, 2006 Share Posted June 18, 2006 [!--quoteo--][div class=\'quotetop\']QUOTE[/div][div class=\'quotemain\'][!--quotec--][b]mktime[/b]Get Unix timestamp for a date (PHP 3, PHP 4, PHP 5) int mktime ( [int hour [, int minute [, int second [, int month [, int day [, int year [, int is_dst]]]]]]] )[/quote][a href=\"http://www.php.net/mktime\" target=\"_blank\"]http://www.php.net/mktime[/a]You've got an extra zero Quote Link to comment https://forums.phpfreaks.com/topic/12296-most-annoying-problem-with-dates/#findComment-46973 Share on other sites More sharing options...
glenelkins Posted June 18, 2006 Author Share Posted June 18, 2006 Well thats now working fine, but its still entering into the database as 0000-00-00 does this have anything to do with changing the format of the date? im trying to enter a uk date rather than us Quote Link to comment https://forums.phpfreaks.com/topic/12296-most-annoying-problem-with-dates/#findComment-47000 Share on other sites More sharing options...
poirot Posted June 18, 2006 Share Posted June 18, 2006 Maybe you are using a MySQL timestamp data type?In this case you shouldn't insert a UNIX timestamp...[a href=\"http://dev.mysql.com/doc/refman/5.0/en/datetime.html\" target=\"_blank\"]http://dev.mysql.com/doc/refman/5.0/en/datetime.html[/a] Quote Link to comment https://forums.phpfreaks.com/topic/12296-most-annoying-problem-with-dates/#findComment-47001 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.