How can I compare two dates in PHP?

前端 未结 13 2022
一整个雨季
一整个雨季 2020-11-22 06:02

How can I compare two dates in PHP?

The date is stored in the database in the following format

2011-10-2

If I wanted to

13条回答
  •  长情又很酷
    2020-11-22 06:45

    first of all, try to give the format you want to the current date time of your server:

    1. Obtain current date time

      $current_date = getdate();

    2. Separate date and time to manage them as you wish:

    $current_date_only = $current_date[year].'-'.$current_date[mon].'-'.$current_date[mday]; $current_time_only = $current_date['hours'].':'.$current_date['minutes'].':'.$current_date['seconds'];

    1. Compare it depending if you are using donly date or datetime in your DB:

      $today = $current_date_only.' '.$current_time_only;

      or

      $today = $current_date_only;

      if($today < $expireDate)

    hope it helps

提交回复
热议问题