Jump to content

Most annoying problem with dates


glenelkins

Recommended Posts

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 etc

here 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-18
DAY: 18 MONTH: 06 YEAR: 2006
DATABASE DATE: 05-12-2017

This is so annoying after writing a big website and this one little thing is not working. Any ideas people?
Link to comment
Share on other sites

[!--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
Link to comment
Share on other sites

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
Link to comment
Share on other sites

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]
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.