Check If Date is Future Date in PHP

    By: Thad Mertz
    2 years ago
    Category: PHPViews: 12

    This tutorial demonstrates you how you can check date is future date in php or not. we will add php check if date is after today. Simple php check if date after today. We will look at 2 examples of php check if date greater than today. Ok, let’s dive ride in. I will give you very simple example how to check if date is future date or not in PHP. so let's see both example with output


    Example 1

    <?php
    
      
    
        $startDate = strtotime(date('Y-m-d', strtotime('2023-11-25') ) );
    
        $currentDate = strtotime(date('Y-m-d'));
    
      
    
        if($startDate > $currentDate) {
    
            echo 'date is a future';
    
        }else{
            echo 'date is in past';
        }
    
      
    
    ?>
    

    Here output will be "date is in future". As i checked it in 2021.


    Example 2

    <?php
    
      
    
        $startDate = strtotime(date('Y-m-d', strtotime('2023-11-25') ) );
    
        $currentDate = strtotime('2021-11-20');
    
      
    
        if($startDate > $currentDate) {
    
            echo 'date is a future';
    
        }
    
      
    
    ?>
    

    Quite similar but does the job.

    Output will be "date is in future".