note 99515 modified in function.date by danbrown
| From: | danbrown@php.net | Date: | Tue, 24 Aug 2010 13:03:28 +0000 |
| Subject: | note 99515 modified in function.date by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-171977@lists.php.net to get a copy of this message | ||
Function to return whether or not a given date falls within British Summer Time:
<?php
function is_bst($date) {
$Year = date("Y", $date);
$MarLast = $Year."-03-31";
$OctLast = $Year."-10-31";
//Find the last Sunday in March
if (date("w", strtotime($MarLast)) == 0) //Sunday
{
$LastMarSun = strtotime($MarLast);
} else {
$LastMarSun = strtotime($MarLast." last sunday");
}
//Find the last Sunday in October
if (date("w", strtotime($OctLast)) == 0) //Sunday
{
$LastOctSun = strtotime($OctLast);
} else {
$LastOctSun = strtotime($OctLast." last sunday");
}
$BSTStart = strtotime(date("Y-m-d", $LastMarSun)." 01:00:00");
$BSTEnd = strtotime(date("Y-m-d", $LastOctSun)." 01:00:00");
return (($date >= $BSTStart) && ($date <= $BSTEnd));
}
?>
--was--
Function to return whether or not a given date falls within British Summer Time:
function is_bst($date) {
$Year = date("Y", $date);
$MarLast = $Year."-03-31";
$OctLast = $Year."-10-31";
//Find the last Sunday in March
if (date("w", strtotime($MarLast)) == 0) //Sunday
{
$LastMarSun = strtotime($MarLast);
} else {
$LastMarSun = strtotime($MarLast." last sunday");
}
//Find the last Sunday in October
if (date("w", strtotime($OctLast)) == 0) //Sunday
{
$LastOctSun = strtotime($OctLast);
} else {
$LastOctSun = strtotime($OctLast." last sunday");
}
$BSTStart = strtotime(date("Y-m-d", $LastMarSun)." 01:00:00");
$BSTEnd = strtotime(date("Y-m-d", $LastOctSun)." 01:00:00");
return (($date >= $BSTStart) && ($date <= $BSTEnd));
}
http://php.net/manual/en/function.date.php