I like those built-in php date expressions like +1 hour
, but for some reason, they fall out of my head all of the time. Besides, none of the IDEs I'm aware of suggest auto-completion facility for that kind of stuff. And, finally, although juggling with those strtotime
and date
functions is no rocket science, I have to google their usage each time I need them.
That's why I like the solution that eliminates (at least mitigates) those issues. Here's how adding x
hours to a date can look like:
(new Future(
new DateTimeFromISO8601String('2014-11-21T06:04:31.321987+00:00'),
new NHours($x)
))
->value();
As a nice bonus, you don't have to worry about formatting the resulting value, it's already is ISO8601 format.
This example uses meringue library, you can check out more examples here.