Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

My PHP scripts are currently an hour out due to BST being in operation (GMT+1).

Is there a way of setting php.ini's date.timezone to keep the time correct for BST/DST, without having to manually modify it when the clocks go back?

Alternatively, if PHP used the server's time, which is correct, that would work. Is there a way to tell it to do so?

share|improve this question

1 Answer 1

up vote 2 down vote accepted

Assuming reasonably-recent PHP, if you define date.timezone correctly via date_default_timezone_set(), PHP will handle the GMT offsets itself. Assuming, on the other hand, that you're stuck with old PHP, you'll have to do one of three things:

  • bite the bullet and upgrade PHP
  • bite the bullet and implement your TZ mechanics yourself (not recommended, but see here for several examples in various shades of godawful), or
  • start doing heretical things like system('date') in your code.

Of those, the clear winning solution is a PHP upgrade. How old is your version, really?

share|improve this answer
    
I'm running PHP Version 5.2.10, is that recent enough? I can upgrade, but presumably if 5.2.10 is new enough for the offset functionality to be in place then there's something else amiss? –  user34542 Jul 15 '10 at 13:17
    
5.2.10 was released June 18, 2009. Have there been BST changes since then? I'm not in the UK, so I wouldn't know. The TZ data is "baked into" PHP, though; it doesn't use /etc/tzdata or equivalent. 5.2.13 is the most recent 5.2 version, if you're concerned about E_DEPRECATED and some of the other changes in 5.3; otherwise, 5.3.2 will be your winner. –  BMDan Jul 15 '10 at 13:27

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.