We all know dates are hard, which is why we let libraries and built-in language features handle them. Right?
Well, turns out you can’t even trust those. I was just writing the following code, that needed to determine the first day of the next month for me. Using PHP’s strtotime
function, this oughtta be easy, right?
$firstDateOfNextMonth = date('Y-m-01', strtotime('+1 month'));
Only, today is August 31st, so PHP actually turned this into 2017-10-01
, because obviously that is correct. And yes, my timezone settings are local – var_dump(date('Y-m-d H:i:s'))
gave me 2017-08-31 17:28:22
.
For comparison, PostgreSQL does what I expect:
# select NOW()+'1 month'::interval;
?column?
-------------------------------
2017-09-30 17:31:25.025405+02
(1 row)
Sighs time to file a bug I guess…