Manngo
Manngo

Reputation: 16281

PHP strtotime Function: first day of this year

I am testing some code using PHP’s strtotime() function, but I can’t work out how PHP is interpreting the following:

strtotime('first day of this year')

I get Tue Sep 01 2015 (currently it is Sunday 27 September in Australia).

Is this some strange new usage of “year” that I was previously unaware of?

Upvotes: 3

Views: 1773

Answers (1)

raina77ow
raina77ow

Reputation: 106385

If you don't mention the month (and you don't), strtotime is built to assume you mean the current month. The same goes with year, btw; that's why it's enough to build your expression as simple as...

strtotime('first day of January');

, as this year will be used if skipped in definition anyway.

Note the difference with...

strtotime('first day of first month');

This will give you October, 1 (in September), as it's the first day of the first month since current.

Upvotes: 4

Related Questions