note 68758 deleted from function.date by danbrown

From: Date: Sun, 17 May 2009 19:06:02 +0000
Subject: note 68758 deleted from function.date by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-155199@lists.php.net to get a copy of this message
Note Submitter: Ron ---- 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.

« previous php.notes (#155199) next »