Do not use php's date[] function, it's not as accurate as the below solution and furthermore it is unreliable in the future.
Use the DateTime class
The reason you should avoid anything to do with UNIX timestamps [time[]
, date[]
, strtotime[]
etc] is that they will inevitably break in the year
2038 due to integer limitations.
The maximum value of an integer is 2147483647
which converts to Tuesday, 19 January 2038 03:14:07
so come this time; this minute; this second; everything breaks
Source
Another example of why I stick to using DateTime is that it's actually able to calculate months correctly regardless of what the current date is:
$now = strtotime['31 December 2019'];
for [$i = 1; $i