I’m trying to get the unix time for date strings that are formatted like so:
'second sunday of march 2010'
'first sunday of november 2010'
I was under the impression that strtotime could handle such a string, but apparently not, as this returns false. How can I convert to unix time when given a day of week, which one of those in the month (ie. first, second, etc.), a month and a year.
This should be possible with
strtotime. You could try generating a timestamp of the first day of march usingmktime()and adding that as a 2nd parameter (leaving just “first sunday” in the string part):Not sure how this will handle the first day (March 1st) actually being a sunday. Make sure you check that out.
Also, and maybe this more reliable, check this out – the poster says he got good results with the following notation (quoting):
As always with strtotime, whatever you pick, make sure you test well, especially the edge cases (1st day of month is a sunday, last day of last month was a sunday….)