Inside this article we will see a basic concept of PHP i.e How to get yesterday date in PHP. Article contains classified information about getting yesterday date from current date in PHP.
We need this concept i.e get yesterday date is when we are creating some record type applications. In PHP there are several functions which provides the function to get yesterday date.
We will see two different methods to get yesterday date.
Learn More –
- How to Get Next Month From Date in PHP Tutorial
- How to Get Previous Month From Date in PHP Tutorial
- How To Install Composer in Ubuntu 18.04 ?
- How To Set Sublime Text Editor to FileZilla as Editor ?
Let’s get started.
Example 1: Get Yesterday date “-1 day”
Create a file index.php at your localhost directory.
Open index.php and write this complete code into it.
<?php $newDate = date('Y-m-d', strtotime('-1 day')); echo $newDate; ?>
Output
2021-11-18
Example 2: Get Yesterday date “yesterday”
Create a file index.php at your localhost directory.
Open index.php and write this complete code into it.
<?php $newDate = date('Y-m-d', strtotime('yesterday')); echo $newDate; ?>
Output
2021-11-18
We hope this article helped you to learn How to Get Yesterday Date in PHP Tutorial in a very detailed way.
Online Web Tutor invites you to try Skillshike! Learn CakePHP, Laravel, CodeIgniter, Node Js, MySQL, Authentication, RESTful Web Services, etc into a depth level. Master the Coding Skills to Become an Expert in PHP Web Development. So, Search your favourite course and enroll now.
If you liked this article, then please subscribe to our YouTube Channel for PHP & it’s framework, WordPress, Node Js video tutorials. You can also find us on Twitter and Facebook.