Strtotime("last tuesday") displays last Monday?

Hi,
This is a bit odd, I am using the following line

echo strtotime(“last tuesday”);

and it outputs 1270508400, which equates to

Monday, April 5th 2010, 23:00:00 (GMT)

I logged into my server and the date and system time are correct, so I guess there is a php setting that is incorrect?

Is there a way to solve this?

Regards

Out of curiosity, what are the outputs of the following?

echo time();
echo strtotime("today");
echo strtotime("last tuesday");
echo strtotime("next tuesday");
echo strtotime("last tuesday + 1 hour");

Monday, April 5th 2010, 23:00:00 (GMT)

I got a bit worried there as it seems its not coping with the spread over daylight saving time, but that was on 28th March (in the UK)

Where in the world are you?

I just sorted the problem, the timestamp websites I am using are in a different timezone…

DOH!!!

I am in Ireland, so GMT.

The reason is due to as you found out, strtotime works with timezones.

In addition when you use “last tuesday” you are actually saying “last tuesday at 00.00 (midnight)”, due to you did not pass any timezone, it can convert this to GMT and you get Monday instead (depends on server timezone).

Its a normal issue when dealing with time functions that support timezones, which can seem odd if your not aware of why it is happening.

That’s not precisely true in the sense that nothing gets converted to GMT. If the timezone is Europe/Dublin (currently equating to British Summer Time, GMT+01:00) then the string used in strtotime, to further TheRedDevil’s example, would have become something like “last tuesday at midnight for Europe/Dublin” giving you the correct Unix timestamp (1270508400) for midnight of last Tuesday in that timezone. Since the timezone is GMT plus one hour, the date/time for that timestamp in GMT would be one hour before Europe/Dublin time: as you saw, 23:00 on the Monday. The Unix timestamp does not change for different timezones: it is the same Unix timestamp right now here in Scotland as in the USA, China, India, or anywhere else in the world.

P.S. You can use date(‘e’) or date_default_timezone_get() to see which timezone is being used in your scripts.

Yes, that is correct. It was a bad choice of words from my side. Thanks for rewriting it into proper English :slight_smile: