Jump to content

[SOLVED] Inserting date into mysql?


JP128

Recommended Posts

Ok, here is all the info...

the column join date is a timestamp.
I insert into that column with a mysql_query, and the now() function.
when I call that date, and try to format it into m/d/Y h:i:s ... it always comes out Dec, 31 1969 4:33:26 PM...
Something that I found on the internet...

POST:
LOL - it says "Googlebot last successfully accessed your home page on Dec 31, 1969" - does that make my site on of the oldest on the net? :)

REPLY
Actually, that date occurs when a timestamp isn't valid...looks like a possible but in the code. ;)
When you use the date() function to format the display of a date and/or time in php, the specified date/time should be in a timestamp format, not as returned from the mysql database.  A timestamp is an int that represents the number of seconds passed since the epoch (01 Jan 1970).

To use the date() function you should convert your returned datetime valye from mysql using the strtotime() function.

try this:

<?php

$time = strtotime($row['joined_date']);
$newTime = date("m/d/Y h:i:s",$time);

?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.