NYCPHP Meetup

NYPHP.org

[nycphp-talk] daylight savings time

Adam Maccabee Trachtenberg adam at trachtenberg.com
Mon Apr 19 11:54:11 EDT 2004


On Mon, 19 Apr 2004, Stephen Musgrave wrote:

> I was wondering if there was a way to find out if the current date/time is
> within the range of daylight savings, even if the server doesn't adjust its
> time for daylight savings time.  I need to be able to switch the offset
> between -120 and -180 automatically.

Does this work?

function isdst($tz) {
    putenv("TZ=$tz");
    $ar = localtime(time(),true);
    putenv('TZ=MST'); // Since you're in Phoenix
    return $ar['tm_isdst'];
}

if (isdst('EST5EDT')) {
  // is dst
} else {
  // isn't dst
}

BTW, there's lots of information about dates, times, time zones, dst,
in Chapter 3 of PHP Cookbook. David is a date and time fiend. :)

-adam

-- 
adam at trachtenberg.com
author of o'reilly's php cookbook
avoid the holiday rush, buy your copy today!



More information about the talk mailing list