note 68758 added to function.date
| From: | Ron at osu1 dot php dot net | Date: | Wed, 09 Aug 2006 17:34:17 +0000 |
| Subject: | note 68758 added to function.date | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-115735@lists.php.net to get a copy of this message | ||
Example 3 is really very bad programming practice. Calling date() more than once and putting the
results together, can cause you to have a date or time that is inconsistent, or just plain invalid,
because the system clock could easily change between the calls.
Instead, call time() once up front to get the timestamp, then pass that into each call to date()
like this:
<?php
$now = time();
$tomorrow = mktime(0, 0, 0, date("m", $now) , date("d", $now)+1,
date("Y", $now));
$lastmonth = mktime(0, 0, 0, date("m", $now)-1, date("d", $now),
date("Y", $now));
$nextyear = mktime(0, 0, 0, date("m", $now), date("d", $now),
date("Y", $now)+1);
?>
By doing this, we ensure that we're using the same system clock sampling for all date/time
field formatting, thereby ensuring the results are consistent.
----
Server IP: 66.163.161.117
Probable Submitter: 38.101.48.18
----
X-Spam-Status: No, hits=3.1 required=5.0 tests=DATE_MISSING,FROM_NO_LOWER
autolearn=no version=2.64
----
Manual Page -- http://www.php.net/manual/en/function.date.php
Edit -- https://master.php.net/note/edit/68758
Del: integrated -- https://master.php.net/note/delete/68758/integrated
Del: useless -- https://master.php.net/note/delete/68758/useless
Del: bad code -- https://master.php.net/note/delete/68758/bad+code
Del: spam -- https://master.php.net/note/delete/68758/spam
Del: non-english -- https://master.php.net/note/delete/68758/non-english
Del: in docs -- https://master.php.net/note/delete/68758/in+docs
Del: other reasons-- https://master.php.net/note/delete/68758
Reject -- https://master.php.net/note/reject/68758
Search -- https://master.php.net/manage/user-notes.php