0

I'm having issue syncing date calculation between PHP and MySQL on my server.

Right now, server time is: Tue Jul 1 12:30:35 EDT 2014 with timezone set to America/New_York

Running SELECT NOW() in MySQL returns 2014-07-01 12:30:54 which shows MySQL date is same as of server.

However, PHP date('I') returns 0 and date('Y-m-d H:i:s T') returns 2014-07-01 11:30:35 EST

any idea what is wrong with PHP here ?

Stephane
  • 4,978
  • 9
  • 51
  • 86
  • See this Q&A => http://stackoverflow.com/q/14423348/ - It might help shed some "light" on the subject; *pardon the pun* ;-) – Funk Forty Niner Jul 01 '14 at 16:36
  • You're setting DST to on with the date("I") which is subtracting an hour from the actual time currently. Always remember "spring forward, fall back" We set the clocks ahead an hour in the spring and we set them back an hour in the fall. – VikingBlooded Jul 01 '14 at 16:39
  • thx guys for your replies; setting the is_daylisght_saving = date("I", future_timestamp) is not working considering I'm using date_default_timezone_set('America/New_York'); to default timezone to EST – Stephane Jul 01 '14 at 16:45
  • 1
    For me, `date_default_timezone_set('America/New_York'); echo date('I');` gives `1` and it's `2014-07-01 12:46:11 EDT`. – Ja͢ck Jul 01 '14 at 16:45
  • Moved all this to a community wiki answer. – O. Jones Jul 01 '14 at 16:57

1 Answers1

2

See this Q&A => PHP date("I") for a future or past date - It might help shed some "light" on the subject; pardon the pun ;-) – Fred -ii- 17 mins ago

You're setting DST to on with the date("I") which is subtracting an hour from the actual time currently. Always remember "spring forward, fall back" We set the clocks ahead an hour in the spring and we set them back an hour in the fall. – VikingBlooded 14 mins ago

thx guys for your replies; setting the is_daylisght_saving = date("I", future_timestamp) is not working considering I'm using date_default_timezone_set('America/New_York'); to default timezone to EST – Stephane Kouakou 8 mins ago

For me, date_default_timezone_set('America/New_York'); echo date('I'); gives 1 and it's 2014-07-01 12:46:11 EDT. – Jack 7 mins ago

yes it works now! thx!!! – Stephane Kouakou 4 mins ago

MySQL, when you SELECT NOW(), honors the present value of the time_zone setting in the server. In PHP you need to make sure it knows the current time zone setting.

Community
  • 1
  • 1
O. Jones
  • 103,626
  • 17
  • 118
  • 172