Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP strtotime Function: first day of this year

Tags:

php

strtotime

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?

like image 316
Manngo Avatar asked Jan 31 '26 02:01

Manngo


1 Answers

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.

like image 119
raina77ow Avatar answered Feb 01 '26 18:02

raina77ow



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!