2013-04-14 121 views
2

我已經制作了一個表單,用戶可以從一個calander中選擇一個日期。它將返回d/m/Y,14,15/2013。根據用戶輸入的日期計算星期六

我需要的是跟進週六日期14/05/2013會有什麼18/05/2013

日期字段稱爲:$_POST['field_3']

我一直strtotime,但掙扎沒有更迭

我已經做了SOFAR:

<?php 

$today = $_POST['field_3']; 

$date = strtotime('d/m/Y','next Saturday', $today); 

$initialString = date('m/d/Y', $date); 

$end = date('m/d/Y', strtotime('next saturday 11:59 pm', $date)); 

echo $today ."<br>"; 
echo $initialString . ' - ' . $end; 

?> 

返回:

14/05/2013

01/01/1970 - 1970年1月3日

+0

注意'strtotime'最多隻有2個參數。 – Boaz

回答

1

非常基本的,但是這可以幫助:

<?php 

$year    = 2013; // use substr() (or other stuff) to set these variables 
$month    = 5; 
$day    = 14; 

$newDate = mktime(0, 0, 0, $month, $day, $year); // creates a date with previous variables 

$dayOfWeek = date('w', $newDate);     // get the weekday number; 0 = sunday, ..., 6 = saturday 

$numberOfDaysTillNextSaturday = (6 == $dayOfWeek) ? 7 : (6 - $dayOfWeek); // how many days until next saturday ? If saturday = 6, otherwise = (Saturday - weekday) 

$nextSaturdayDate = $newDate + (86400 * $numberOfDaysTillNextSaturday); // creates a new date corresponding to next saturday 

$nextSaturdayString = date("d/m/Y", $nextSaturdayDate);      // formats the new date as (day)/(month)/(year) 

echo $nextSaturdayString;             // echoes the string 
?> 
+0

非常感謝,您在一天的這個時候指出了我的正確方向。現在是上午10點50分。 我不得不修改一些以從窗體中獲得正確的輸入,但是你關於subst()的提示確實幫了我很多。 現在我做到了: $ datum = $ _POST ['field_3']; $ year = substr($ datum,6); //使用substr()(或其他的東西)來設置這些變量 $ month = substr($ datum,4,2); $ day = substr($ datum,0,2); 它的工作原理是它應該工作。 Best 73's Frank – user2279057

相關問題