note 94746 added to function.date
| From: | brandon@php.net | Date: | Sun, 22 Nov 2009 14:14:34 +0000 |
| Subject: | note 94746 added to function.date | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-163174@lists.php.net to get a copy of this message | ||
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.
----
Server IP: 69.147.83.197
Probable Submitter: 70.88.230.126
----
Manual Page -- http://www.php.net/manual/en/function.date.php
Edit -- https://master.php.net/note/edit/94746
Del: integrated -- https://master.php.net/note/delete/94746/integrated
Del: useless -- https://master.php.net/note/delete/94746/useless
Del: bad code -- https://master.php.net/note/delete/94746/bad+code
Del: spam -- https://master.php.net/note/delete/94746/spam
Del: non-english -- https://master.php.net/note/delete/94746/non-english
Del: in docs -- https://master.php.net/note/delete/94746/in+docs
Del: other reasons-- https://master.php.net/note/delete/94746
Reject -- https://master.php.net/note/reject/94746
Search -- https://master.php.net/manage/user-notes.php