YYYY-MM-DD hh:mm:ss to unixtime
Snippet
Instead of being asleep at 17:13 on 3 August 2011, kitt created this:
Convert a MYSQL datetime string of the format "YYYY-MM-DD hh:mm:ss" into a unixtime integer in PHP (if epoch, that is: date > 1970-01-01).
$birthday = '1980-06-01 00:00:00'; $birthdayunx = mktime(0, 0, 0, substr($birthday, 5, 2), substr($birthday, 8, 2), substr($birthday, 0, 4)); // the next day $nextdayunx = mktime(0, 0, 0, substr($birthday, 5, 2), (substr($birthday, 8, 2) + 1), substr($birthday, 0, 4)); $nextdaystr = strftime("Y-m-d H:i:s", $nextdayunx); /* FROM: int mktime ([ int $hour = date("H") [, int $minute = date("i") [, int $second = date("s") [, int $month = date("n") [, int $day = date("j") [, int $year = date("Y") [, int $is_dst = -1 ]]]]]]] ) If you can, use mysql date functions: SELECT duedate, DATE_ADD(FROM_TIMESTAMP(duedate), INTERVAL 1 DAY) AS nextday FROM ...; */
Add new comment