How to Compare Dates in php?

前端 未结 3 957
野的像风
野的像风 2020-12-07 06:40

i need code to compare date in php

  1. Input date should be a valid date
  2. input date should not be less than the current date.
  3. i need to give time
3条回答
  •  北荒
    北荒 (楼主)
    2020-12-07 07:05

    This is a late answer. since there is no exact answer to the question here, I'm providing this solution here.

    You can do it in this way

    $date1 = strtotime("2007-02-20"); // your input
    $date2 = strtotime("today"); //today
    if($date1 < $date2) {
        echo " input date is in the past";
    }
    

    strtotime converts the string in to the unix timestamp integer.

提交回复
热议问题