NYCPHP Meetup

NYPHP.org

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

David Mintz dmintz at davidmintz.org
Fri Aug 27 13:14:43 EDT 2004


Can I suggest an optimization? Use explode(). "If you don't require the
power of regular expressions, it is faster to use explode(), which doesn't
incur the overhead of the regular expression engine."
--http://us3.php.net/split

Or:  use a preg_split(), a regex, and make it a two-liner?

list($year,$month,$day,$hour,$minute,$second) = preg_split('/[- :]/',$mysqlDateTime);

Or: consider mysql's own UNIX_TIMESTAMP(date) function in the first place.


On Fri, 27 Aug 2004, Joseph Crawford Jr. wrote:

> 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);
> }
>

---
David Mintz
http://davidmintz.org/

        "Anybody else got a problem with Webistics?" -- Sopranos 24:17



More information about the talk mailing list