开发者

Why are these changes to date not taking effect?

I have this code that should be changing the day of the output, but I'm not getting any change. Can anyone see what is wrong?

<?php 
$tempStartDate = "2011-07-04 15:00:00";
$TempDaysFromEvent = "-14";

$newtempStartDate = explode(" ", $tempStartDate);
echo "New Temp Start Date: ".$newtempStartDate[0];
echo "<br>";
list($year, $month, $day) = explode("-", $newtempStartDate[0]);
echo $year." ". $month. " ". $day;
echo "<br>";

$tempStartDate  =  $tempEndDate  =  date("Y-m-d", mktime(0,0,0,$month,($day+$tempDaysFromEvent),$year));
echo "TempStart Date:".$tempStartDate."<br>";

?>

This is giving me this output:

New Temp Start Date: 2011-07-04
2011 07 04
TempStart Date:2011-开发者_运维知识库07-04

But I would expect it to give me:

New Temp Start Date: 2011-07-04
2011 07 04
TempStart Date:2011-06-20


you have a capital when you define $TempDaysFromEvent so change it to this

$tempStartDate  =  $tempEndDate  =  date("Y-m-d", mktime(0,0,0,$month,($day+$TempDaysFromEvent),$year));


You should be getting this notice:

Notice: Undefined variable: tempDaysFromEvent in C:\tmp\test.php on line 12

Your variable is actually $TempDaysFromEvent. Variables in PHP are case sensitive.


You have a typo there

$tempDaysFromEvent instead of $TempDaysFromEvent


A much less complicated solution:

$tempStartDate = "2011-07-04 15:00:00";
print date('Y-m-d H:i:s', strtotime('-14 days', strtotime($tempStartDate)));
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜