Re: Newbie question... date.
| From: | Ray | Date: | Tue, 13 Jan 2004 20:40:07 +0000 |
| Subject: | Re: Newbie question... date. | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-174480@lists.php.net to get a copy of this message | ||
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"!