2013-04-24 58 views
1

我有以下腳本做一些日期操作:可變天添加到特定日期

function indate($leavedate){ 
    if($leavedate){ 
    $enddate=$leavedate[0]['LoppumisPvm'];//This prints 23 Apr 
    $endday=date('d',strtotime($enddate));//this prints 23 
    $endmonth=date('M',strtotime($enddate));// This prints Apr 

    $additional_days=$endday-15;// This prints 8 
    $end = strtotime(date("d M", strtotime("15 Jan")) . " +$additional_days days"); 
    echo $end; 

我試圖讓該變量$end這將額外的天數添加到特定日期(有鑑於1月15日)..它打印1358179200,而不是..

回答

1

你有一個混淆了一個額外的strtotime電話和一些不好定位的括號。將您的代碼更改爲:

$end = date("d M", strtotime("15 Jan + {$additional_days} days")); 
0

你需要改變:

$end = strtotime(date("d M", strtotime("15 Jan")) . " +$additional_days days"); 

爲:

$end = date("d M",strtotime(date("d M", strtotime("15 Jan")) . " +$additional_days days"));