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

Reading Time: 3 minutes
3,379 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.

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.