note 47133 deleted from function.strtotime by sean
| From: | sean@php.net | Date: | Wed, 08 Dec 2004 19:41:48 +0000 |
| Subject: | note 47133 deleted from function.strtotime by sean | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-81543@lists.php.net to get a copy of this message | ||
Note Submitter: martin dot goldinger at netserver dot ch
----
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)));
?>