PHP Check if date is past to a certain date given in a certain format

后端 未结 4 1735
温柔的废话
温柔的废话 2020-12-14 14:40

I have a php event\'s calender which queries the database to get the dates.

I display the event date using:

$event[\'date\']

and t

4条回答
  •  情话喂你
    2020-12-14 15:26

    @Satch3000 You've accepted the wrong answer as a right solution ( @Amal Murali )

    Please see the output, Here I input the today date but it returns current date as past date.

    Output will be

    DateTime Object
    (
        [date] => 2017-09-14 00:00:00.000000
        [timezone_type] => 3
        [timezone] => UTC
    )
    DateTime Object
    (
        [date] => 2017-09-14 07:12:52.000000
        [timezone_type] => 3
        [timezone] => UTC
    )
    date is in the past
    

    Solution

    $Date1 = strtotime(date('Y-m-d', strtotime('2017-09-15') ) ).' ';
    $Date2 = strtotime(date('Y-m-d'));
    
      if($Date1 < $Date2) {
            echo 'date is in the past';
        }
    

提交回复
热议问题