note 47133 added to function.strtotime

From: Date: Thu, 04 Nov 2004 10:05:57 +0000
Subject: note 47133 added to function.strtotime
Groups: php.notes 
Request: Send a blank email to php-notes+get-79588@lists.php.net to get a copy of this message
It seems that [, int now] is converted to a date only in strtotime() and not to a datetime. So if you add 4 hours to a datetime (MySQL Format) you will have the datetime at 04 AM. Solution: just generate the timestamp without hours, minutes and seconds and add this values in strtotime(). (PHP 5.0.2) <? list ($date, $time) = explode(' ', '2004-11-04 10:55:58'); list ($Y, $m, $d) = explode('-', $date); list ($H, $i, $s) = explode(':', $time); $hours = 4; // doesn't work print date("Y-m-d H:i:s", strtotime('+' . $hours . ' hours', mktime($H, $i, $s, $m, $d, $Y))); // works fine print date("Y-m-d H:i:s", strtotime('+' . ($hours + $H) . ' hours ' . $i . ' minutes ' . $s . ' seconds', mktime(0, 0, 0, $m, $d, $Y))); ?> ---- Manual Page -- http://www.php.net/manual/en/function.strtotime.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+47133 Delete -- http://master.php.net/manage/user-notes.php?action=delete+47133&report=yes Reason: bad code -- http://master.php.net/manage/user-notes.php?action=delete+47133&report=yes&reason=bad+code Reason: spam -- http://master.php.net/manage/user-notes.php?action=delete+47133&report=yes&reason=spam Reason: useless example -- http://master.php.net/manage/user-notes.php?action=delete+47133&report=yes&reason=useless+example Reason: contains commercial links -- http://master.php.net/manage/user-notes.php?action=delete+47133&report=yes&reason=contains+commercial+links Reason: useless note -- http://master.php.net/manage/user-notes.php?action=delete+47133&report=yes&reason=useless+note Reject -- http://master.php.net/manage/user-notes.php?action=reject+47133&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#79588) next »