note 44062 added to function.mktime

From: Date: Wed, 14 Jul 2004 03:42:10 +0000
Subject: note 44062 added to function.mktime
Groups: php.notes 
Request: Send a blank email to php-notes+get-73194@lists.php.net to get a copy of this message
This may not be the best, but is one way to find out whether the given date falls in Daylight Savings Time or not. mktime is again used in combination with date() function. <?php // here is the date. We wont worry about the time. $processdate = "07/04/2004 14:45"; // calling the function. // 1 means the date is in a daylight savings time // 0 means the date is not in a daylight savings time echo daylight($processdate); // now the function function daylight($mydate) { // separating the date and time $datetime = explode(" ",$mydate); // exploding the components of date $dateexplode = explode("/",$datetime[0]); // if the date is between Jan-Mar, NO DAYLIGHT // if the date is between Nov-Dec, NO DAYLIGHT if ($dateexplode[0]<4 or $dateexplode[0]>10) { return 0; } // if the date is not in the above zone, lets see // if the date is between May-Sep, DAYLIGHT elseif ($dateexplode[0]>4 and $dateexplode[0]<10) { return 1; } else { // we are going to pull out what date is a sunday // then we compare our date's day-of-month with the day-that-is-sunday $interestday = 0; // lets see what happens in april - first sunday of the month if ($dateexplode[0]==4) { // looping the first seven days to see what day is a sunday for ($i=1; $i<=7; $i++) { $myday = date("w",mktime(0,0,0,$dateexplode[0],$i,$dateexplode[2])); if ($myday==0) $interestday = $i; } // now that we got what day is a sunday, lets see // if our date's day-of-month is greater than this or not // if it is greater, then DAYLIGHT if ($dateexplode[1]>=$interestday) return 1; else return 0; } // lets see what happens in october - last sunday of the month elseif ($dateexplode[0]==10) { // looping the first seven days to see what day is a sunday for ($i=25; $i<=31; $i++) { $myday = date("w",mktime(0,0,0,$dateexplode[0],$i,$dateexplode[2])); if ($myday==0) $interestday = $i; } // now that we got what day is a sunday, lets see // if our date's day-of-month is greater than this or not // if it is less, then DAYLIGHT if ($dateexplode[1]<=$interestday) return 1; else return 0; } } } ?> ---- Manual Page -- http://www.php.net/manual/en/function.mktime.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+44062 Delete -- http://master.php.net/manage/user-notes.php?action=delete+44062&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+44062&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#73194) next »