note 96013 added to function.date
| From: | eamon at gizzle dot co dot uk | Date: | Wed, 03 Feb 2010 09:25:59 +0000 |
| Subject: | note 96013 added to function.date | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-165614@lists.php.net to get a copy of this message | ||
To Find the real month is something that can annoy some of us. here's a function to make this
easier.
print_r( realmonth('2010-05-01 19:30:00') );
function realmonth($date)
{
// current time
$time = strtotime($date);
// current time info
$currentTimeInfo = (object)getdate($time);
// the week difference
$weeks = (4 * 7 * 24 * 60 * 60);
$nextTime = date("Y-m-d H:i:s",($time + $weeks));
// compare the dates
$date = (object)array(
'start' => $currentTimeInfo,
'end' => (object)getdate(strtotime($nextTime))
);
if($date->start->mon == $date->end->mon)
{
$nextTime = date("Y-m-d H:i:s",($time + $weeks + (7 * 24 * 60 * 60)));
}
return (object)array(
'start' => $currentTimeInfo,
'end' => getdate(strtotime($nextTime))
);
}
Result:
stdClass Object
(
[start] => stdClass Object
(
[seconds] => 0
[minutes] => 30
[hours] => 19
[mday] => 1
[wday] => 6
[mon] => 5
[year] => 2010
[yday] => 120
[weekday] => Saturday
[month] => May
[0] => 1272738600
)
[end] => Array
(
[seconds] => 0
[minutes] => 30
[hours] => 19
[mday] => 5
[wday] => 6
[mon] => 6
[year] => 2010
[yday] => 155
[weekday] => Saturday
[month] => June
[0] => 1275762600
)
)
Thanks
Eamon Straughn
----
Server IP: 92.48.74.199
Probable Submitter: 78.105.107.181
----
Manual Page -- http://www.php.net/manual/en/function.date.php
Edit -- https://master.php.net/note/edit/96013
Del: integrated -- https://master.php.net/note/delete/96013/integrated
Del: useless -- https://master.php.net/note/delete/96013/useless
Del: bad code -- https://master.php.net/note/delete/96013/bad+code
Del: spam -- https://master.php.net/note/delete/96013/spam
Del: non-english -- https://master.php.net/note/delete/96013/non-english
Del: in docs -- https://master.php.net/note/delete/96013/in+docs
Del: other reasons-- https://master.php.net/note/delete/96013
Reject -- https://master.php.net/note/reject/96013
Search -- https://master.php.net/manage/user-notes.php