British Summer Time? (BST) (Rated 4)Description:
This PHP function will let you know if we are currently in British Summer Time.
Sounds useless doesn't it. Trust me, it has some uses. For example some British hosting companies keep their servers set to GMT and do not adjust for BST. The reason being is that it would be unfair on their international clients. Fair enough.
The European Union has now adopted The Ninth European Parliament and Council Directive on Summer Time Arrangements in which it states that British Summer (or daylight saving) time will be kept between the last Sunday in March to the last Sunday in October. The changes will take place at 1am GMT. Code starts here
<?
// declare some start variables
$ThisYear = (date("Y"));
$MarStartDate = ($ThisYear."-03-25");
$OctStartDate = ($ThisYear."-10-25");
$MarEndDate = ($ThisYear."-03-31");
$OctEndDate = ($ThisYear."-10-31");
//work out the Unix timestamp for 1:00am GMT on the last Sunday of March, when BST starts
while ($MarStartDate <= $MarEndDate)
{
$day = date("l", strtotime($MarStartDate));
if ($day == "Sunday"){
$BSTStartDate = ($MarStartDate);
}
$MarStartDate++;
}
$BSTStartDate = (date("U", strtotime($BSTStartDate))+(60*60));
echo "BST this year starts at 1:00am GMT on ";
echo date("l, dS M", $BSTStartDate);
echo "<br>";
//work out the Unix timestamp for 1:00am GMT on the last Sunday of October, when BST ends
while ($OctStartDate <= $OctEndDate)
{
$day = date("l", strtotime($OctStartDate));
if ($day == "Sunday"){
$BSTEndDate = ($OctStartDate);
}
$OctStartDate++;
}
$BSTEndDate = (date("U", strtotime($BSTEndDate))+(60*60));
echo "BST this year ends at 1:00am GMT on ";
echo date("l, dS M", $BSTEndDate);
echo "<br>";
//Check to see if we are now in BST
$now = mktime();
if (($now >= $BSTStartDate) && ($now <= $BSTEndDate)){
echo "We are now in BST";
}
else {
echo "We are now in GMT";
}
?>
Submitted by Devscripts on 07-04-2004 8:38 |