I am currently on CDT

run strtotime() of the following string now returns are:

2009-11-17 9:00:00 am
1258470000

(note: Correct return. And the return value is using CST timezone automatically even the server is on CDT now.)

2009-11-17 9:00:00 am CST
1258470000

(note: Correct return. And the return value is using CST timezone, the server is on CDT and I also asking to use CST.)


My problem is with the following:

2009-11-17 9:00:00 am CDT
1258466400

Even CDT ends after 2009-11-01, but strtotime on this "2009-11-17 9:00:00 am CDT" will still return CDT time, due to the string specifically ask so.

Should "2009-11-17 9:00:00 am CDT" still return 1258470000 the same as "
2009-11-17 9:00:00 am CST"? due to CDT already ends on that date?

Because, say the server is on CDT now, and if I am working on events which is on Eastern timezone, when I try to convert the event date (either EDT or EST depends on the date) to unix timestamp, I have to add either EDT or EST, otherwise, the unix timestamp is for CDT/CST date as default, which will be wrong.

But due to I am getting these events' date from database or so, I don't know it will be either EDT or EST, I will only know that it is East Time Zone, so if I give EDT, "2009-11-17 9:00:00 am EDT", actually I would expect is "2009-11-17 9:00:00 am EST".

Should "2009-11-17 9:00:00 am EDT" return same value as "2009-11-17 9:00:00 am EST" due to EDT already ends on 2009-11-17? But php strtotime() returns different values for "2009-11-17 9:00:00 am EDT" and "2009-11-17 9:00:00 am EST".

How do you solve the problem that if you are on CDT/CST timezone, and you are trying to covert date (Eastern time, EDT/EST) to unix timestamp but you don't know it is EDT or EST?

Or this is the old problem php has with the timezone. And the only solution is using this http://www.php.net/manual/en/function.date-default-timezone-set.php instead?

Thanks!

    This is the reason I always store dates and times in UTC.

    blackhorse wrote:

    But php strtotime() returns different values for "2009-11-17 9:00:00 am EDT" and "2009-11-17 9:00:00 am EST".

    Of course, because they're different timezones. One is Eastern Standard Time (eastern United States I'm going to wildly guess) and the other is Eastern Daylight Time. And there's an hour's difference between them. If you specify one, why would you expect PHP to use the other?

      The problem is that I am working with the 3rd party database. And they are in the Eastern Time Zone, and my server is in the Central Time Zone. So when I convert their date into unix timestamp, I have to tell which timezone this date is in. The problem is that I cannot tell before hands if they are in Eastern Daylight Timezone or Eastern Standard Timezone, it will depend on the date retreived from 3rd party database.

      I was expecting that because Daylight timezone ends before 2009-11-17 9:00:00 am, php will know that.

      I think that is the date_default_timezone_set() function works. Is that the reason that EDT EST CDT these kind timeszone depreciated being used in the strtotime(), and we are supposed to use the date_default_timezone_set() instead?

        Actually, what you're saying is that the third-party database has times stored using two different timezones - EDT and EST - and they jump back and forth between them.

        I guess what you could do is construct a DateTime object with the appropriate region set (whatever its proper name is), use it to read the dates and convert them to UTC or Unix timestamps, then convert them back to what is appropriate for your region.

          Say in the 3rd party database, there are two dates

          2009-10-28 18:00 (it should be EDT)
          2009-11-03 18:00 (it should be EST)

          If my server is on the same time zone with my client (3rd party database), then I don't need to do anything. I can just go ahead to use the strtotime etc. It is default to my time zone and so the client time zone.

          But due to I am on Central time. So I have to tell which time zone it is when I convert the above two dates.

          My point is that I cannot use strtotime with EDT or EST as part of parameter.

          What I should do is use date_default_timezone_set
          Such as date_default_timezone_set('America/New York');

          Then it will take care of the EDT or EST for me, when I convert the above two dates.

            Write a Reply...