phpmady Posted August 24, 2011 Share Posted August 24, 2011 Hi guys, $T_Start_Date = "2011-10-23"; $P_Days = "30"; I tried this Its working: $T_End_Date = date('Y-m-d', strtotime("+$P_Days days"); but why am not getting this: $T_End_Date = date($T_Start_Date, strtotime("+$P_Days days")); thanks Quote Link to comment https://forums.phpfreaks.com/topic/245549-date-calculation/ Share on other sites More sharing options...
jcbones Posted August 24, 2011 Share Posted August 24, 2011 Because date() expects a format for the first argument. Try: <?php $T_End_Date = date('Y-m-d', strtotime("+ $P_Days days",$T_Start_Date)); Quote Link to comment https://forums.phpfreaks.com/topic/245549-date-calculation/#findComment-1261163 Share on other sites More sharing options...
phpmady Posted August 25, 2011 Author Share Posted August 25, 2011 But i am geting the result like this 1970-03-02 Quote Link to comment https://forums.phpfreaks.com/topic/245549-date-calculation/#findComment-1261976 Share on other sites More sharing options...
requinix Posted August 25, 2011 Share Posted August 25, 2011 And strtotime() expects a timestamp for the second argument Pick: "$T_Start_Date + $P_Days days" strtotime("+ $P_Days days", strtotime($T_Start_Date)) Quote Link to comment https://forums.phpfreaks.com/topic/245549-date-calculation/#findComment-1261987 Share on other sites More sharing options...
Psycho Posted August 25, 2011 Share Posted August 25, 2011 Although requinix's solution should work, this is simpler: $T_Start_Date = "2011-10-23"; $P_Days = "30"; $T_End_Date = date('Y-m-d', strtotime("$T_Start_Date +$P_Days days")); echo $T_End_Date; Output: 2011-11-22 Quote Link to comment https://forums.phpfreaks.com/topic/245549-date-calculation/#findComment-1261991 Share on other sites More sharing options...
jcbones Posted August 25, 2011 Share Posted August 25, 2011 And strtotime() expects a timestamp for the second argument Pick: "$T_Start_Date + $P_Days days" strtotime("+ $P_Days days", strtotime($T_Start_Date)) GAHHHH!!!! Gonna have to quit posting without sleep. Quote Link to comment https://forums.phpfreaks.com/topic/245549-date-calculation/#findComment-1261997 Share on other sites More sharing options...
xyph Posted August 25, 2011 Share Posted August 25, 2011 @mjdamato - not to mention twice as fast, which is a big deal when working with PHP's date functions. Quote Link to comment https://forums.phpfreaks.com/topic/245549-date-calculation/#findComment-1262026 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.