On Tuesday 13 January 2004 13:57, DL wrote:
> Hi all,
>
> I was wondering how you get the year, month, and day from a
> timestamp. (mySQL timestamp, Eg: 20040113130137)  What PHP
> function(s) do I use?  An example would be great....
>
> Cheers,
> David

http://www.php.net/manual/en/function.strtotime.php
copied from the comments (formatting may be lost)

scott at pigandcow dot com
29-Dec-2003 09:54
Unfortunately, strtotime() can't convert mysql timestamps of the form 
YYYYMMDDhhmmss (the default 14 character timestamp).  Here's a 
function to do it for you:

function convert_timestamp ($timestamp, $adjust="") {
   $timestring = substr($timestamp,0,8)." ".
                 substr($timestamp,8,2).":".
                 substr($timestamp,10,2).":".
                 substr($timestamp,12,2);
   return strtotime($timestring." $adjust");
}

Remember that the $adjust string needs to be properly spaced- "+ 30 
days", not "+30days"!

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to