How To Check If Date is a Past Date in PHP Tutorial

Share this Article
Reading Time: 3 minutes
2,068 Views

Inside this article we will see the concept to check if date is a past date in php. There are several options in php which helps to check if date is a past date. Article contains classified information about PHP tutorial to check if date is a past date.

If you are looking for an article which helps you to check if date is a past date then you are at right place to learn in a very easy way.

Learn More –

Let’s get started.


Example 1: Check Date is Past Date from Current Date

Create a file index.php at your localhost directory.

Open index.php and write this complete code into it.

<?php

$startDate = strtotime(date('Y-m-d', strtotime('2021-10-17')));
$currentDate = strtotime(date('Y-m-d'));

if ($startDate < $currentDate) {
    echo 'Your date is of past';
}

Output

Your date is of past

Example 2: Check Date is Past Date from Date

Create a file index.php at your localhost directory.

Open index.php and write this complete code into it.

<?php

$startDate = strtotime(date('Y-m-d', strtotime('2021-10-17')));
$endDate = strtotime('2021-11-20');

if ($startDate < $endDate) {
    echo 'Your date is of past';
}

Output

Your date is of past

We hope this article helped you to learn How To Check If Date is a Past Date in PHP Tutorial in a very detailed way.

Buy Me a Coffee

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.

Was this post helpful?

PHP Web Development Courses on Offer in just $4
PHP Web Development Courses on Offer in just $4