2017-03-06 94 views
0

請告訴我,如果下面的方法是可靠的檢查,如果當前的日期範圍之間是這樣可靠checkl如果當前日期是在一個範圍內PHP

function check_in_range($start_date, $end_date) 
{ 
      // Convert to timestamp 
      $start_ts = strtotime($start_date); 
      $end_ts = strtotime($end_date)+86400; 
      //added 86400 to check for that particular date too 

      $timeNow = strtotime("now"); 

      // Check that user date is between start & end 
      return (($timeNow >= $start_ts) && ($timeNow <= $end_ts)); 
    } 

回答

0

我會建議使用日期時間對象如此:

function check_in_range($start_date, $end_date) 
    { 
     $startDate = new \DateTime($start_date); 

     $endDate = new \DateTime($end_date); 
     $endDate->add(new \DateInterval('PT86400')); 

     return ((time() >= $startDate->getTimeStamp()) && (time() <= $endDate->getTimestamp())); 
    } 
相關問題