PHP Date/Time Check with BST

by Keiron on June 3, 2005

function BSTCheck() {
$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));

//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));

//Check to see if we are now in BST
$now = mktime();
return (($now >= $BSTStartDate) && ($now <= $BSTEndDate)) ? TRUE : FALSE;
}

$DST = (BSTCheck()) ? 3600 : 0;
$time = gmdate("H:i", time() + $DST);
$night = ((date("H")>=17) OR (date("H")<5)) ? TRUE : FALSE;

Tag Me:
  • Digg
  • del.icio.us
  • Furl
  • StumbleUpon
  • Technorati
  • Sphinn
  • TwitThis

{ 0 comments… add one now }

There are no comments yet...

Kick things off by filling out the form below ↓

Leave a Comment

You can use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>