Learn How to show Yesterday’s date in PHP

In this tutorials we are going to learn how to display Yesterday’s date in PHP.

You are going to use two PHP date functions for this:

1. strtotime();
2. date();

strtotime() is a function which converts any English string to a UNIX timestamp.

date() function is used to format the timestamp. For Instance:

1. d/m/y
2. m/d/y

To show Today’s date. You can simply use the date() function:

But to show Yesterday’s date you have to use strtotime() and date():

It’s basically subtracting of a day in a Plain English, so the strtotime() function will change the Plain English text to the Timestamp, and then date() function to format the date.

Likewise you can subtract or add days, weeks, months. Its really very simple in PHP when comparing other languages as far as I know.

 

Related Posts

Leave a Reply