How to Check If Date is Past Date in 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...
Hardik Savani
I'm a full-stack developer, entrepreneur and owner of ItSolutionstuff.com. I live in India and I love to write tutorials and tips that can help to other artisan. I am a big fan of PHP, Laravel, Angular, Vue, Node, Javascript, JQuery, Codeigniter and Bootstrap from the early stage. I believe in Hardworking and Consistency.
We are Recommending you
- How to Get Full Day Name from Date in PHP?
- How to Get Previous Month from Date in PHP?
- How to Get Next Month Date in PHP?
- How to Get Tomorrow Date in PHP?
- How to Get Yesterday Date in PHP?
- PHP Subtract Seconds from Time Example
- How to Subtract Minutes from DateTime in PHP?
- How to Subtract Hours from DateTime in PHP?
- How to Add Seconds to Time in PHP?