有開始和存儲在數據庫中的這種格式的結束日期:如果這兩個中的任何一個等於
start date= 20121004 //4th October 2012
end date= 20121004 //16th November 2012
,所以我可以使用的日期格式:
$date = date("Ymd"); // returns: 20121004
來確定何時顯示而不是顯示
重新填充我的更新輸入框的使用:
$start=(str_split($stdate,4));// START DATE: splits stored date into 2x4 ie: 20121209 = 2012 1209
$syr = $start[0];// re first half ie: 2012 which is the year
$start2 = $start[1];//re second half ie: 1209
$start3=(str_split($start2,2));// splits second half date into 2x2 ie: 1209 = 12 09
$smth = $start3[0]; // first half = month ie: 12
$sday = $start3[1]; // second half = day ie: 09
$expiry=(str_split($exdate,4)); ///SAME AGAIN FOR EXPIRY DATE ...
$xyr = $expiry[0];
$expiry2 = $expiry[1];
$expiry3=(str_split($expiry2,2));
$xmth = $expiry3[0];
$xday = $expiry3[1];
其工作正常,但我需要重新填充輸入框用於顯示這樣
<option value="01">January</option`>
在數據庫中的日期使用
if ($smth==01):$month='January'; endif;
if ($xmth==01):$month='January'; endif;
// if the start and/or expiry month number = 01 display $month as January
if ($smth==02):$smonth='February'; endif;
if ($xmth==02):$smonth='February'; endif;
if ($smth==03):$month='March'; endif;
<select name="stmonth" class="input">
<option value="<?=$smth?>"><?=$month?></option>
...
</select>
月份有顯示如果上述的一個更簡單的方法EQUALS,而不必每次寫同一行兩次一次$ smth AND $ xmth? re:if ($smth **and or** $xmth ==01):$month='January'; endif;
更新==================== = 找到一種更簡單的方式來顯示而不使用嵌套的if循環。無關原來的問題,但可能是有用的人:
$months = array(X,January,February,March,April,May,June,July,August,September,October,November,December);
///第一個記錄假人保持代碼的相對
//simple swith command
switch ($smth){
case 1: $s = 1; break;
case 2: $s = 2; break;
case 3: $s = 3; break;
case 4: $s = 4; break;
case 5: $s = 5; break;
case 6: $s = 6; break;
case 7: $s = 7; break;
case 8: $s = 8; break;
case 9: $s = 9; break;
case 10: $s = 10; break;
case 11: $s = 11; break;
case 12: $s = 12; break;
default; }
switch ($xmth){
case 1: $x = 1; break;
case 2: $x = 2; break;
case 3: $x = 3; break;
case 4: $x = 4; break;
case 5: $x = 5; break;
case 6: $x = 6; break;
case 7: $x = 7; break;
case 8: $x = 8; break;
case 9: $x = 9; break;
case 10: $x = 10; break;
case 11: $x = 11; break;
case 12: $x = 12; break;
default; }
則顯示是這樣的:
<select name="stmonth" class="input">
<option value="<?=$smth?>"><?=$months[$s]?></option>
使用'DateTime'對象會救你很多頭痛。 –