DEV Community

Discussion on: Go vs PHP for short JSON-retrieving code

Collapse
 
crimsonmed profile image
Médéric Burlet

You could simplify the way you get yesterday fairly easily with the following:

$yesterday = date('Y-m-d',strtotime("-1 days"));

You could also use:

$yesterday = date('Y-m-d', strtotime("yesterday"));
Collapse
 
rodiongork profile image
Rodion Gorkovenko

Wow, thanks :) You see, though I'm not professional PHP dev and thus I don't know many such nice "short-cuts"... Thanks a lot!

Collapse
 
crimsonmed profile image
Médéric Burlet

PHP has a very nice way to handle dates you can do things like:

new DateTime('first day of this year')
new DateTime('last day of this month')
new DateTime('last day of December this year')
new DateTime('last day of December this year +1 years');

Thread Thread
 
rodiongork profile image
Rodion Gorkovenko

That made my day! They probably spent significant efforts on parsing this :) On the other hand it is easier to use than whimsical functions and constants in go "time" package. Thank you once more!