I am looking for a function eiether php built or custime made to check if the current time is in Daylight Saving Time" or not.

I have date_default_timezone_set('UTC');and I store all date as UTC Timestamps. This all works fine for my site but I need to alter a few times where Daylight Saving must taken into account.

Is there a simple inbuilt php function or a custom made one like (eg xxx = (IsDSTInoperation,"UK")
So if it is 0100UTC, Do a DST check for UK, if DST is in operation the add 1 hour to the current UTC time)

    One way would be to do a date_default_timezone_set() to the location of interest, then get the result of date('I'), which will be "1" if DST, else "0".

      Personally I prefer not changing default timezone

      $tz = new DateTimeZone('Europe/London');
      
      # 0 hour diff from UTC => no daylight savings
      $secondsFromUTC = $tz->getOffset(new DateTime('2011-01-01 14:00'));
      echo $secondsFromUTC / 3600 . '<br/>';
      
      # 1 hour diff from UTC => daylight savings
      $secondsFromUTC = $tz->getOffset(new DateTime());
      echo $secondsFromUTC / 3600;
      

      And using DateTime and DateTimeZone, you don't even have to check if a place currently uses DST or not. As you can see, the conversion is automatic (in this example, conversion from a place with DST to one in the same timezone but without DST.

      $el = new DateTimeZone('Europe/London');
      $an = new DateTimeZone('Africa/Bamako');
      
      $dt = new DateTime('now', $el);
      printf('London (now - summer time): &#37;s<br/>', $dt->format('H:i:s'));
      $dt->setTimeZone($an);
      printf('Bamako equivalent: %s<br/>', $dt->format('H:i:s'));
      
      
      $dt = new DateTime('2011-01-01 11:00', $el);
      printf('London (jan 01, 11:00): %s<br/>', $dt->format('H:i:s'));
      $dt->setTimeZone($an);
      printf('Bamako (equivalent): %s<br/>', $dt->format('H:i:s'));
      

        Thanks for the replies, NozDog seems the easiest to just check if a zone is in DST or not.

        Thanks

          Write a Reply...