MasterACE14 Posted November 15, 2008 Share Posted November 15, 2008 I'm trying to echo the date/time from a column in my database, It is echo'ing, but it's not displaying the correct time/date. The column in my database is a timestamp data type. Here is my function I use on the date when I grab it from the database. <?php function prettydate($format,$datetime) { $year = substr( $datetime, 0, 4 ); $mon = substr( $datetime, 4, 2 ); $day = substr( $datetime, 6, 2 ); $hour = substr( $datetime, 8, 2 ); $min = substr( $datetime, 10, 2 ); $sec = substr( $datetime, 12, 2 ); return date($format,mktime( $hour, $min, $sec, $mon, $day, $year ) ); } and I grab the date like so... <?php echo prettydate("M j, H:i",$row["date"]); I should be getting something like... Nov 14, 23:28 at the present time. But I am getting stuff like this... Nov 1, 14:02 any help is greatly appreciated. Regards, ACE Link to comment https://forums.phpfreaks.com/topic/132799-solved-working-with-time-and-date-getting-wrong-output/ Share on other sites More sharing options...
n3ightjay Posted November 15, 2008 Share Posted November 15, 2008 if its a timestamp try this instead : <?php function prettydate($format,$datetime) { return date($format,strtotime($datetime) ); } Link to comment https://forums.phpfreaks.com/topic/132799-solved-working-with-time-and-date-getting-wrong-output/#findComment-690622 Share on other sites More sharing options...
MasterACE14 Posted November 15, 2008 Author Share Posted November 15, 2008 that worked. Thanks n3ightjay appreciated. Regards, ACE Link to comment https://forums.phpfreaks.com/topic/132799-solved-working-with-time-and-date-getting-wrong-output/#findComment-690628 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.