2011-09-28 68 views
0

任何人都可以教我一個函數或腳本或一些相關示例,其中只允許輸入多少天?我有一個選擇日期開始和日期結束的日期選擇器...我只希望用戶在指定的時間/日期範圍內輸入,如果用戶重疊,它會提示用戶他們只能從一定範圍內輸入的時間。在PHP中驗證日期

Ex。我只會允許28天。

Scenario1:

Date from: 2011-09-01 
Date to: 2011-09-31 

Result: (prompt) you are only allowed to input within 28 days. 

Scenario2:

Date from: 2011-09-01 
Date to: 2011-09-20 

Result: it will proceed to another page. 

回答

1

如果你有> = PHP 5.3 ...

$startDate = new DateTime('2011-09-01'); 
$endDate = new DateTime('2011-09-31'); 

$diff = $startDate->diff($endDate); 

if ($diff->d > 28) { 
    // More than 28 days. 
}