sasnaktiv
asked on
GMT Daylight Savings Time discrepancy !!!
I have a php program that executes certain tasks at certain hours during the day.
Those tasks are scheduled using Greenwich Mean Time + TimeZones.
The tasks are performed in the United States & Canada. Everything has been working on time until this past weekend.
Now all the tasks are an hour late. Here's the problem. GMT went off Daylight Savings Time and on to Standard Time this past weekend, Sunday October 30th.
But the United States will remain on Daylight Savings until Sunday November 6th. After that all the tasks will be on time, but it's important that I compensate for the time change during this week when the two differ.
How can I do that just for this week?
Additionally I will have the opposite problem in the Spring when GMT goes back on Daylight Savings Time on Sunday March 25 2012 and the U.S. goes on Daylight Savings Time March 11, 2012.
Thanks for the help,
Sas
Below is an example of what's working properly now:
Those tasks are scheduled using Greenwich Mean Time + TimeZones.
The tasks are performed in the United States & Canada. Everything has been working on time until this past weekend.
Now all the tasks are an hour late. Here's the problem. GMT went off Daylight Savings Time and on to Standard Time this past weekend, Sunday October 30th.
But the United States will remain on Daylight Savings until Sunday November 6th. After that all the tasks will be on time, but it's important that I compensate for the time change during this week when the two differ.
How can I do that just for this week?
Additionally I will have the opposite problem in the Spring when GMT goes back on Daylight Savings Time on Sunday March 25 2012 and the U.S. goes on Daylight Savings Time March 11, 2012.
Thanks for the help,
Sas
Below is an example of what's working properly now:
<?php
{
$my_agent='SAS';
$Today00=date("Y-m-d"); //0000-00-00
$Today0=date("Y-n-j"); // 0000-0-0
$CurrentGMT_Hour = gmdate("G") ;
date_default_timezone_set('Europe/London');
$Today00 = date("Y-m-d",time());
$GMT_Hour = date("H",time());
if ($GMT_Hour == 00){$GMT_Hour = 24;} else {$GMT_Hour = date("H",time());}
}
//CONNECT TO MySQL DB
//SET TABLE NAME
// ........ BEGIN DEFINE WHO TO CALL ..............//
$PerformTask= "participants WHERE (
(current_status='a' AND next_task_date='$Today00' AND GMT_task_hour='$GMT_Hour' AND my_agent='$my_agent')
OR (current_status='a' AND GMT_taskDate2='$Today00' AND GMT_task_hour2='$GMT_Hour' AND my_agent='$my_agent')
OR (current_status='a' AND GMT_taskDate3='$Today00' AND GMT_task_hour3='$GMT_Hour' AND my_agent='$my_agent')
OR (current_status='a' AND GMT_taskDate4='$Today00' AND GMT_task_hour4='$GMT_Hour' AND my_agent='$my_agent')
OR (current_status='a' AND next_task_date='$Today0' AND GMT_task_hour='$GMT_Hour' AND my_agent='$my_agent')
OR (current_status='a' AND GMT_taskDate2='$Today0' AND GMT_task_hour2='$GMT_Hour' AND my_agent='$my_agent')
OR (current_status='a' AND GMT_taskDate3='$Today0' AND GMT_task_hour3='$GMT_Hour' AND my_agent='$my_agent')
OR (current_status='a' AND GMT_taskDate4='$Today0' AND GMT_task_hour4='$GMT_Hour' AND my_agent='$my_agent')
)
"; // etc. ...
Hmm... Is Europe/London the same as GMT? I have not tested this yet, but it might not be the same.
See: http://www.laprbass.com/RAY_temp_sasnaktiv.php
The correct strategy will be to know the client location and make the appropriate default timezone setting for each request.
Best of luck with it, ~Ray
The correct strategy will be to know the client location and make the appropriate default timezone setting for each request.
Best of luck with it, ~Ray
<?php // RAY_temp_sasnaktiv.php
error_reporting(E_ALL);
echo "<pre>";
// DIFFERENT TIME ZONES
$tzs = array
( 'UTC'
, 'Europe/London'
, 'Europe/Dublin'
, 'Atlantic/Reykjavik'
, 'Atlantic/Bermuda'
, 'America/Halifax'
, 'America/New_York'
, 'America/Chicago'
, 'America/Argentina/Salta'
, 'America/Edmonton'
, 'America/Boise'
, 'America/Denver'
, 'America/Phoenix'
, 'America/Los_Angeles'
, 'America/Juneau'
, 'America/Anchorage'
, 'America/Adak'
)
;
// TEST THE TIMEZONES FOR DAYLIGHT SAVINGS TIME
foreach ($tzs as $tz)
{
date_default_timezone_set($tz);
echo PHP_EOL . $tz;
if (date('I')) echo " IS IN DAYLIGHT SAVINGS TIME";
}
GMT does not change. Europe/London is GMT minus 1 for daylight savings.
http://www.timeanddate.com/worldclock/clockchange.html?n=136
You seem to base all daylight savings changes based on your local which as you see is not accurate.
Presumably your system's OS has the updated timezone information such that using the suggested options other provided which is assigning/setting the time zone on which you want to work and then access the date/time will be more accurate and likely avoid this issue.
You can use the above link to make sure that the time zone settings you are using are accurate/current.
http://www.timeanddate.com/worldclock/clockchange.html?n=136
You seem to base all daylight savings changes based on your local which as you see is not accurate.
Presumably your system's OS has the updated timezone information such that using the suggested options other provided which is assigning/setting the time zone on which you want to work and then access the date/time will be more accurate and likely avoid this issue.
You can use the above link to make sure that the time zone settings you are using are accurate/current.
ASKER
Hi Ray & Arnold,
I think I have a much simpler solution. Let me work on it. If it functions the way I think it will, I'll post it for you.
Sas
I think I have a much simpler solution. Let me work on it. If it functions the way I think it will, I'll post it for you.
Sas
ASKER
I think I've got the solution, but I can't remember or find the php code that will give me the "last Sunday in October" and the "first Sunday in November" during the current year. And on the flip side, I also need the code for the "second Sunday in March" along with the "last Sunday in March" during the current year.
Can you help?
Sas
Find out which day is November 1st same with March. Then you can get all the rest.
i.e. if the 1st is a Saturday Sunday is 2nd
if 1st is Monday, 7th is Sunday
Similar for March The lowest number for second sunday in March it can be is 8th with 14 as the max
Sure you are looking for Last Sunday in March and not second Sunday in March?
http://www.codingforums.com/showthread.php?t=170497
i.e. if the 1st is a Saturday Sunday is 2nd
if 1st is Monday, 7th is Sunday
Similar for March The lowest number for second sunday in March it can be is 8th with 14 as the max
Sure you are looking for Last Sunday in March and not second Sunday in March?
http://www.codingforums.com/showthread.php?t=170497
ASKER
Hi Arnold,
There is an easier way to do this. I just can't remember the code and it is very simple. The link you send does not seem to apply.
Sas
There is an easier way to do this. I just can't remember the code and it is very simple. The link you send does not seem to apply.
Sas
See these date strings:
http://www.laprbass.com/RAY_strtotime.php?s=November+1+-+1+Sunday
http://www.laprbass.com/RAY_strtotime.php?s=November+1+%2B+1+Sunday
See also these date strings:
http://www.laprbass.com/RAY_strtotime.php?s=March+1+%2B+2+Sunday
http://www.laprbass.com/RAY_strtotime.php?s=April+1+-+1+Sunday
The article explains it all, and shows several examples of how to use strtotime() with commonsense expressions about dates.
https://www.experts-exchange.com/Web_Development/Web_Languages-Standards/PHP/A_201-Handling-date-and-time-in-PHP-and-MySQL.html
BTW, the expression "last Sunday" gives the value for "last Sunday," so that is why we do not try to say something like "last Sunday in March."
http://www.laprbass.com/RAY_strtotime.php?s=last+Sunday
http://www.laprbass.com/RAY_strtotime.php?s=November+1+-+1+Sunday
http://www.laprbass.com/RAY_strtotime.php?s=November+1+%2B+1+Sunday
See also these date strings:
http://www.laprbass.com/RAY_strtotime.php?s=March+1+%2B+2+Sunday
http://www.laprbass.com/RAY_strtotime.php?s=April+1+-+1+Sunday
The article explains it all, and shows several examples of how to use strtotime() with commonsense expressions about dates.
https://www.experts-exchange.com/Web_Development/Web_Languages-Standards/PHP/A_201-Handling-date-and-time-in-PHP-and-MySQL.html
BTW, the expression "last Sunday" gives the value for "last Sunday," so that is why we do not try to say something like "last Sunday in March."
http://www.laprbass.com/RAY_strtotime.php?s=last+Sunday
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
If you have clients in London, date_default_timezone_set( 'Europe/Lo ndon'); would make sense. But I thought you had clients in the USA and Canada. Why not use the correct PHP timezone settings for your clients? You will be looking at this problem every year until you fix it, and you will be writing code that will suddenly fail if the government changes the boundaries of daylight savings time (has happened several times in my life). Or what if you get a client in Phoenix, where they do not observe daylight savings time? The right solution is so easy, it seems a shame not to choose it.
Anyway, you have the answer to the question along with demonstration scripts that show you how to understand and correct the problem, so I will sign off now. Best of luck with it, ~Ray
Anyway, you have the answer to the question along with demonstration scripts that show you how to understand and correct the problem, so I will sign off now. Best of luck with it, ~Ray
ASKER
I've requested that this question be closed as follows:
Accepted answer: 0 points for sasnaktiv's comment http:/Q_27428738.html#37080195
for the following reason:
My own solution will do until I can go deeper if the need be.
Accepted answer: 0 points for sasnaktiv's comment http:/Q_27428738.html#37080195
for the following reason:
My own solution will do until I can go deeper if the need be.
ASKER
My own solution will do until I can go deeper if the need be.
https://www.experts-exchange.com/Web_Development/Web_Languages-Standards/PHP/A_201-Handling-date-and-time-in-PHP-and-MySQL.html