note 72366 modified in function.strtotime by danbrown
| From: | danbrown@php.net | Date: | Mon, 18 May 2009 02:26:51 +0000 |
| Subject: | note 72366 modified in function.strtotime by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-155653@lists.php.net to get a copy of this message | ||
A hint not to misunderstand the second parameter:
The parameter "[, int now]" is only used for strings which describe a time difference to
another timestamp.
It is not possible to use strtotime() to calculate a time difference by passing an absolute time
string, and another timestamp to compare to!
Correct:
<?php
$day_before = strtotime("+1 day", $timestamp);
# result is a timestamp relative to another
?>
Wrong:
<?php
$diff = strtotime("2007-01-15 11:40:00", time());
# result it the timestamp for the date in the string;
# because the string contains an absolute date and time,
# the second parameter is ignored!
# instead, use:
$diff = time() - strtotime("2007-01-15 11:40:00");
?>
--was--
A hint not to misunderstand the second parameter:
The parameter "[, int now]" is only used for strings which describe a time difference to
another timestamp.
It is not possible to use strtotime() to calculate a time difference by passing an absolute time
string, and another timestamp to compare to!
Correct:
$day_before = strtotime("+1 day", $timestamp);
# result is a timestamp relative to another
Wrong:
$diff = strtotime("2007-01-15 11:40:00", time());
# result it the timestamp for the date in the string;
# because the string contains an absolute date and time,
# the second parameter is ignored!
# instead, use:
$diff = time() - strtotime("2007-01-15 11:40:00");
http://php.net/manual/en/function.strtotime.php