note 80470 modified in function.mktime by danbrown

From: Date: Sun, 20 Jul 2008 03:31:38 +0000
Subject: note 80470 modified in function.mktime by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-142070@lists.php.net to get a copy of this message
Taking a sample from a fellow poster a bit up, I've made this quite simple MYSQL date to timestamp which will convert both date or date/time fields. <?php function MySQLtoTimestamp($mysqlDate) { if (strlen($mysqlDate) > 10) { list($year, $month, $day_time) = explode('-', $mysqlDate); list($day, $time) = explode(" ", $day_time); list($hour, $minute, $second) = explode(":", $time); $ts = mktime($hour, $minute, $second, $month, $day, $year); } else { list($year, $month, $day) = explode('-', $mysqlDate); $ts = mktime(0, 0, 0, $month, $day, $year); } return $ts; } ?> --was-- Taking a sample from a fellow poster a bit up, I've made this quite simple MYSQL date to timestamp which will convert both date or date/time fields. function MySQLtoTimestamp($mysqlDate) { if (strlen($mysqlDate) > 10) { list($year, $month, $day_time) = explode('-', $mysqlDate); list($day, $time) = explode(" ", $day_time); list($hour, $minute, $second) = explode(":", $time); $ts = mktime($hour, $minute, $second, $month, $day, $year); } else { list($year, $month, $day) = explode('-', $mysqlDate); $ts = mktime(0, 0, 0, $month, $day, $year); } return $ts; } http://php.net/manual/en/function.mktime.php

« previous php.notes (#142070) next »