PASSWORD RESET

Your destination for complete Tech news

PHP

How to get yesterday’s date in PHP?

1.19K 0
< 1 min read

You can use the PHP date() function along with strtotime() to get yesterday’s date in PHP. Here’s an example code snippet:

$yesterday = date("Y-m-d", strtotime("-1 day"));
echo $yesterday;

In this example, we’re using the “Y-m-d” format for the date, which outputs the date in the format of “YYYY-MM-DD”. The strtotime() function takes a string argument, which in this case is “-1 day”, indicating that we want to subtract one day from the current date.

The $yesterday variable will now contain yesterday’s date in the format “YYYY-MM-DD”, which you can use in your PHP code as needed.

Leave A Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.