2017-09-13 28 views
-1

我有一個日期格式如下:年月日添加天/周的格式化的日期

我似乎無法找到一種方法,以便能夠在數週內添加到這個日期,我曾嘗試以下:

$quote_start_date = $job['quote_authorised']; 

$newdate = date($quote_start_date, strtotime('+5 weeks')); 

但是,新的日期是相同的,什麼是最簡單的方法來添加星期這樣格式化的日期?

+1

是什麼'$ quote_start_date'的輸出?請告訴我們。 –

+0

你可以寫下你的輸入和準確的期望輸出嗎? – sinaza

+0

查看http://php.net/manual/en/datetime.add.php – Scuzzy

回答

1

的第二個參數自時代以來需要幾秒鐘。只是在幾秒鐘加5個星期的時間,即:

$newdate = date($format, strtotime($quote_start_date) + (5 * 7 * 24 * 60 * 60)); 

或者只是使用恆定值「3024000」

$newdate = date($format, strtotime($quote_start_date) + 3024000); 
1

date的第一個參數預計爲您輸出日期字符串的格式。我認爲你正在尋找以下:

$quote_start_date = $job['quote_authorised']; 
$newdate = date("Ymd", strtotime('+5 weeks', strtotime($quote_start_date))); 

的更有效的方法是在一個星期內使用固定的值的秒數,而不是依賴於PHP解析附加strtotime功能:

$quote_start_date = $job['quote_authorised']; 
$newdate = date("Ymd", strtotime($quote_start_date) + 3024000); 
+0

這是非常無效,你要求PHP解析'+5周',它將返回一個常數值'3024000'。只需在第一個「strtotime」調用中添加3024000。 – HostFission

+0

當然。答案已更新。 – kinggs

0

它的一個演示:

$date = new Date(); 
$nextDate = new Date($date.setTime($date.getTime() + 1 * 86400000)); 
// here 1 is number of day . 
+0

「將週數添加到日期」,而不是將當前時間加上幾周。 – HostFission