note 94746 deleted from function.date by danbrown

From: Date: Mon, 23 Nov 2009 15:35:16 +0000
Subject: note 94746 deleted from function.date by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-163201@lists.php.net to get a copy of this message
Note Submitter: brandon at php dot net ---- In response to the note by przemeq at gmail dot com, you can do this with far fewer lines of code: <?php function dayOfWeek($date) { $epoch = strtotime($date); if(!$epoch) { trigger_error('Unable to convert date to epoch value', E_USER_WARNING); return; } return date('w', $epoch); } ?> This is considerably less code, even when you include sanity checks (which the last note does not). It also conviently supports any date (November 22nd, 2009, 11/22/2009, 2009-22-11, now, Next Thursday, One Month From Today, etc.). As a note, Saturday == 6, != 7. There are seven days, and date() counts from 0, meaning the highest integer value can be 6.

« previous php.notes (#163201) next »