ItSolutionStuff.com

How to Check If Date is Past Date in PHP?

By Hardik Savani • May 14, 2024
PHP

In this example, i will show you how to check date is past date in php. step by step explain php check if date is before today. you can see php check if date before today. we will help you to give example of php check if date less than today.

I will give you very simple example how to check if date is past date or not in PHP. so let's see both example with output:

Example 1: PHP Check Date is Past Date from Current Date

index.php

<?php

$startDate = strtotime(date('Y-m-d', strtotime('2021-11-15') ) );

$currentDate = strtotime(date('Y-m-d'));

if($startDate < $currentDate) {

echo 'date is in the past';

}

?>

Output:

date is in the past

Example 2: PHP Check Date is Past Date from Date

index.php

<?php

$startDate = strtotime(date('Y-m-d', strtotime('2021-11-15') ) );

$currentDate = strtotime('2021-11-20');

if($startDate < $currentDate) {

echo 'date is in the past';

}

?>

Output:

date is in the past

i hope it can help you...

Tags: PHP
Hardik Savani

Hardik Savani

I'm a full-stack developer, entrepreneur, and founder of ItSolutionStuff.com. Passionate about PHP, Laravel, JavaScript, and helping developers grow.

📺 Subscribe on YouTube

We Are Recommending You

How to Get Full Day Name from Date in PHP?

Read Now →

How to Get Previous Month from Date in PHP?

Read Now →

How to Get Next Month Date in PHP?

Read Now →

How to Get Tomorrow Date in PHP?

Read Now →

How to Get Yesterday Date in PHP?

Read Now →

PHP Subtract Seconds from Time Example

Read Now →

How to Subtract Minutes from DateTime in PHP?

Read Now →

How to Subtract Hours from DateTime in PHP?

Read Now →

How to Add Seconds to Time in PHP?

Read Now →