Re: MySQL datetime extraction
| From: | Yasir Malik | Date: | Sat, 19 Jul 2003 19:27:54 +0000 |
| Subject: | Re: MySQL datetime extraction | ||
| References: | 1 2 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-155912@lists.php.net to get a copy of this message | ||
Thanks. Here's how I did it:
$str = "2003-12-13 12:23:34"
$b = localtime(strtotime($str), 1);
printf("seconds: ".$a["tm_sec"]."\n");
On Sat, 19 Jul 2003, John W. Holmes wrote:
> Date: Sat, 19 Jul 2003 14:28:00 -0400
> From: John W. Holmes <holmes072000@charter.net>
> To: Yasir Malik <ymalik@cs.stevens-tech.edu>
> Cc: php-general@lists.php.net
> Subject: Re: [PHP] MySQL datetime extraction
>
> Yasir Malik wrote:
> > Given a date in MySQL datetime format, how do I extract the elements?
> > That is get the month, day, year, hour, ...
>
> You could do it in the query using DATE_FORMAT(), MONTH(), YEAR(), etc.
>
> You can do it in PHP by sending the MySQL timestamp through strtotime()
> and then using date() to extract each component.
>
> --
> ---John Holmes...
>
> Amazon Wishlist: www.amazon.com/o/registry/3BEXC84AB3A5E/
>
> PHP|Architect: A magazine for PHP Professionals – www.phparch.com
>
>
>
>