note 116316 added to class.dateinterval
| From: | cmygind at tsccorpdotcom | Date: | Thu, 11 Dec 2014 14:05:27 +0000 |
| Subject: | note 116316 added to class.dateinterval | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-201113@lists.php.net to get a copy of this message | ||
You can create a series of dates starting with the first day of the week for each week, if you wish
to populate list box on your web page with this date math. Use the absolute abs( ) function to
convert negative numbers generated from dates in the past.
<?php
$TwoWeeksAgo = new DateTime(date("Ymd"));
$TwoWeeksAgo->sub(new DateInterval('P'.abs (
(7-date("N")-14)).'D'));
$LastWeek = new DateTime(date("Ymd"));
$LastWeek->sub(new DateInterval('P'.abs (
(7-date("N")-7)).'D'));
$ThisWeek = new DateTime(date("Ymd"));
$ThisWeek->add(new DateInterval('P'.abs ( (7-date("N"))).'D'));
echo 'Start of This week is '.$ThisWeek->format('l
m/d/Y').'<br/>';
echo 'Start of Last week is '.$LastWeek->format('l
m/d/Y').'<br/>';
echo 'Start of 2 weeks ago is '.$TwosWeekAgo->format('l
m/d/Y').'<br/>';
?>
----
Server IP: 72.52.91.14
Probable Submitter: 38.124.94.10
----
Manual Page -- http://php.net/manual/en/class.dateinterval.php
Edit -- https://master.php.net/note/edit/116316
Del: integrated -- https://master.php.net/note/delete/116316/integrated
Del: useless -- https://master.php.net/note/delete/116316/useless
Del: bad code -- https://master.php.net/note/delete/116316/bad+code
Del: spam -- https://master.php.net/note/delete/116316/spam
Del: non-english -- https://master.php.net/note/delete/116316/non-english
Del: in docs -- https://master.php.net/note/delete/116316/in+docs
Del: other reasons-- https://master.php.net/note/delete/116316
Reject -- https://master.php.net/note/reject/116316
Search -- https://master.php.net/manage/user-notes.php