July 2, 201016 yr I've got my dates stored in a MySQL table in TIMESTAMP format. I then pull these dates from the table using PHP, and I can echo the TIMESTAMP date in PHP exactly as it appears in the MySQL table. E.G. 2010-07-01 14:26:00 What I'd like to do is convert the TIMESTAMP format '2010-07-01 14:26:00' to something like '1st Jul'. This is the code I'm using, but it keeps on displaying '1st Jan'? $mySQLdate = mysql_result($result,$j-1,'date'); echo date( 'jS M', $mySQLdate );
July 2, 201016 yr date() takes a unix-timestamp as it's argument, not a SQL date string, what you need to do is convert it with strtotime() echo date('jS M',strtotime($mySQLdate));
July 2, 201016 yr Author Excellent, thanks for your help. I'm a little confused as to how the PHP code was being processed then in my orignal example. $mySQLdate = mysql_result($result,$j-1,'date'); echo date('jS M', $mySQLdate); Was it ignoring the $mySQLdate variable in the date('jS M', $mySQLdate) statement, or giving this variable a new value based on the Unix Timestamp?
July 2, 201016 yr it was attempting to convert the string "2010-07-01 14:26:00" into an integer using php's Integer Casting, this results in 2010, in unix time this represents the time Thursday, January 1, 1970 12:33:30 am UTC (2010 seconds from the epoch)
Create an account or sign in to comment