Posted By

sveggiani on 09/21/10


Tagged

strings not-mine


Versions (?)

Convert MySQL date to UNIX timestamp


 / Published in: PHP
 

URL: http://www.vision.to/convert-mysql-date-to-unix-timestamp.php

  1. <?php
  2. // from MySQL to UNIX timestamp
  3. function convert_datetime($str)
  4. {
  5.  
  6. list($date, $time) = explode(' ', $str);
  7. list($year, $month, $day) = explode('-', $date);
  8. list($hour, $minute, $second) = explode(':', $time);
  9.  
  10. $timestamp = mktime($hour, $minute, $second, $month, $day, $year);
  11.  
  12. return $timestamp;
  13. }
  14. ?>

Report this snippet  

Comments

RSS Icon Subscribe to comments
Posted By: dob on September 21, 2010

or you could just use: ``

Posted By: dob on September 21, 2010

strtotime()

Posted By: sveggiani on September 28, 2010

The problem with strtotime() is that behaves different depending of your "locale" configuration. So I prefer this safer method.

You need to login to post a comment.