Reputation: 498
I'm trying to get the timestamps of various days using the php strtotime function but am having problems. For instance, trying to get the day and month before (eg) the second sunday in March.
I've run some tests and get the following results:
$day1 = date('j', strtotime('second sunday of march yesterday'));
$month1 = date('n', strtotime('second sunday of march yesterday'));
This produces 28 and 2 respectively, not 7 and 3.
I've moved the word "yesterday" and get the following:
$day1 = date('j', strtotime('yesterday second sunday of march'));
$month1 = date('n', strtotime('yesterday second sunday of march'));
This does produce the right result, but when I do
$day1 = date('j', strtotime('first sunday of november yesterday'));
$month1 = date('n', strtotime('first sunday of november yesterday'));
In this case, with "yesterday" at the end of the string, it produces the correct date, 31 and 10 . It produces this result even if "yesterday" is at the end.
Am I missing something? Why does one of these need "yesterday" to be at the start of the string?
Upvotes: 1
Views: 346
Reputation: 8343
This is not yesterday
- this is +- 1 day
. For some reason, -1 day
does not work.
I can't say what PHP is doing with the yesterday, but as the English version makes no sense, it is not too surprising that PHP's interpretation of it doesn't make sense either. ;)
Upvotes: 2