2016-09-10 99 views
-1

我只想問比較2日,我有3個日期,日期的今天,date_of_needed和2周領先於其他日期,我有這樣的代碼:邏輯在PHP

$DateNeeded = $this->input->post('date_of_need'); 
$newDate = date("m-d-y",strtotime("+2 weeks")); 
$d = $this->input->post('dateavail'); 

當我贊同這3個日期,我想出了這一點:

Date Needed: 9/12/16 
Date to be Reserved: 9/24/16 
Date Today: 9/10/16 

我想有一個邏輯,這將使我無法保留一個產品如果它小於2周。我將如何做到這一點? 這裏是我的邏輯

if($DateNeeded < $newDate){ 
    echo "You need to reserve 2 weeks ahead!"; 
} 

但它不是工作..謝謝你幫我

+0

你可以用的strtotime比較2個日期。 http://stackoverflow.com/questions/8722806/how-to-compare-two-dates-in-php –

回答

0

試試這個

$DateNeeded = strtotime($$DateNeeded); 
$newDate = date("m-d-y",strtotime("+2 weeks")); 
newDate_1 = strtotime($newDate); 

if($DateNeeded < $newDate){ 
    echo "You need to...." 
}