Get tomorrow’s date using PHP.

This is a short guide on how to get tomorrow’s date using PHP. Essentially, we want to get the next date after the current one. Fortunately, this is pretty easy to do with PHP.

Let’s start off with an example using the strtotime function!

Getting tomorrow’s date using the strtotime function.

In most cases, PHP’s strtotime function will understand the textual description of the date that you want. As a result, you can simply pass in “+1 day” and the function will return the Unix timestamp for tomorrow’s date.

In the snippet above, we retrieved the Unix timestamp for tomorrow’s date. After that, we converted the timestamp into a date string.

Note that you can also pass the word “tomorrow” into the strtotime function:

Essentially, “tomorrow” and “+1 day” are the exact same thing. Both will result in strtotime returning a timestamp representing the next day.

Getting tomorrow’s date using PHP’s DateTime object.

If you’re looking for an object-orientated approach to this problem, then you can use the DateTime object.

Firstly, we created a DateTime object representing today’s date. Secondly, we created a DateInterval object with “P1D” as the period. In plain English, P1D means a “period of 1 day”.

Finally, we added our interval onto the current date.

And that’s it! Hopefully, this tutorial helped you to solve your problem. For more information on this subject, you should check out my guide on adding days to a date using PHP.

Related: Get next year’s date using PHP.

Facebook Comments