NYCPHP Meetup

NYPHP.org

[nycphp-talk] Selecting unix timestamp from MySQL (3.x)datetimefield

Joseph Crawford Jr. jcrawford at codebowl.com
Fri Aug 27 08:51:09 EDT 2004


here is some sample code, however i am afraid it cannot be done within an
sql statement

function getTimestamp($mysqlDateTime) {
     $data = split(" ", $mysqlDateTime);
     $datedata = $data[0];
     $timedata = data[1];

     $date = split("-", $datedata);
     $time = split(":", $timedata);

     $year = $date[0];
     $month = $date[1];
     $day = $date[2];
     $hour = $time[0];
     $minute = $time[1];

     return mktime($hour, $minute, 0, $month, $day, $year);
}

there may be easier ways if so someone share ;)

Joe Crawford Jr
----- Original Message ----- 
From: "Hans Zaunere" <hans at nyphp.com>
To: "NYPHP Talk" <talk at lists.nyphp.org>
Sent: Thursday, August 26, 2004 11:23 PM
Subject: RE: [nycphp-talk] Selecting unix timestamp from MySQL
(3.x)datetimefield



> > I wish this were a DATE_FORMAT option...
> >
> > How do I turn a MySQL DATETIME field (0000-00-00 00:00) into a Unix
> > timestamp?
> >
> > Strtotime() choked.
>
> a MySQL function:
>
> UNIX_TIMESTAMP('0000-00-00 blah...')

That will do it, but also keep in mind the potential for date overflow,
since a UNIX timestamp has a smaller range than a DATETIME column.

UNIX_TIMESTAMP('1935-05-29')

for example

H
_______________________________________________
New York PHP Talk
Supporting AMP Technology (Apache/MySQL/PHP)
http://lists.nyphp.org/mailman/listinfo/talk
http://www.newyorkphp.org





More information about the talk mailing list