MySQL Forums
Forum List  »  PHP

Re: Useful Snippet
Posted by: Jonathan Stephens
Date: June 15, 2005 10:20AM

This provides more information, as you can see if you do a var_dump() on the result:

function from_mysql_timestamp($timestamp)
{
list($year, $month, $day, $hour, $minute, $second) = preg_split("/\D/", $timestamp);
return getdate( mktime($hour, $minute, $second, $month, $day, $year) );
}

Or you could use MySQL's date and time functions: http://dev.mysql.com/doc/mysql/en/date-and-time-functions.html

E.g.

SELECT YEAR( NOW() ) - YEAR(ts_column) FROM table;

(BTW, in your function, there's no need to make the return value a global variable.)

Jon Stephens
MySQL Documentation Team @ Oracle
Orlando, Florida, USA

MySQL Dev Zone
MySQL Server Documentation
Oracle

Options: ReplyQuote


Subject
Written By
Posted
June 14, 2005 09:14AM
Re: Useful Snippet
June 15, 2005 10:20AM
June 15, 2005 12:37PM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.