iPixel Posted March 16, 2010 Share Posted March 16, 2010 I'm trying to figure this out, but i'm not sure why this is happening. A form passes a date ie: 2010-03-16 the next page has to find out what the date 7 days from the passed date is. This will echo the date of next week based on todays date. echo date("Y-m-d", strtotime("next week")); Why isnt this giving me the correct date echo date("Y-m-d", strtotime("2010-03-10","next week")); This echoes : 1969-12-31 LOL Any help is much appreciated. Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/195475-quick-date-strtotime-help/ Share on other sites More sharing options...
ksugihara Posted March 16, 2010 Share Posted March 16, 2010 /*Display the beginning of the next week*/ echo date("Y-m-d", strtotime("next week")) /*Display 7 days from now */ echo date("Y-m-d", strtotime("+1 week")); Quote Link to comment https://forums.phpfreaks.com/topic/195475-quick-date-strtotime-help/#findComment-1027193 Share on other sites More sharing options...
iPixel Posted March 16, 2010 Author Share Posted March 16, 2010 My issues is displaytime "next week" from a given date, not "now" now i already got working. it's more like show me next week from "2010-06-15". That's my issue. Basically you are given dates ranging from the beggining of time to god knows when in format YYYY-MM-DD and i need php to tell me what +1 week from then is. Quote Link to comment https://forums.phpfreaks.com/topic/195475-quick-date-strtotime-help/#findComment-1027201 Share on other sites More sharing options...
ksugihara Posted March 16, 2010 Share Posted March 16, 2010 So write your own function. <?php $sevenDays = addTime(date("Y-m-d"), "next week"); echo $sevenDays; function addTime($date, $time) { $date = explode('-', $date); $day = $date[2]; switch($time) { case "next week": $timeAdvance = 7; break; case "tomorrow": $timeAdvance = 1; break; } $futureDate = $day + $timeAdvance; $futureDate = $date[0] . "-" . $date[1] . "-" . $futureDate; return($futureDate); } ?> Quote Link to comment https://forums.phpfreaks.com/topic/195475-quick-date-strtotime-help/#findComment-1027208 Share on other sites More sharing options...
iPixel Posted March 16, 2010 Author Share Posted March 16, 2010 I was avoiding writing functions. I figured php had some quick and snazzy way to do it with a predefined function. I'm a little confused here... where's the date input. Quote Link to comment https://forums.phpfreaks.com/topic/195475-quick-date-strtotime-help/#findComment-1027214 Share on other sites More sharing options...
ksugihara Posted March 16, 2010 Share Posted March 16, 2010 $date = date("Y-m-d"); $sevenDays = addTime($date, "next week"); better? Quote Link to comment https://forums.phpfreaks.com/topic/195475-quick-date-strtotime-help/#findComment-1027218 Share on other sites More sharing options...
iPixel Posted March 16, 2010 Author Share Posted March 16, 2010 !!!! DOH !!! this is why they have people like you in this world to help people like me get our butts in gear!!! Thank You! Quote Link to comment https://forums.phpfreaks.com/topic/195475-quick-date-strtotime-help/#findComment-1027224 Share on other sites More sharing options...
iPixel Posted March 16, 2010 Author Share Posted March 16, 2010 Unfortunately 2010-05-28 + 7 = 2010-05-35 with this function, but i know how to fix that part. Thanks Again! Quote Link to comment https://forums.phpfreaks.com/topic/195475-quick-date-strtotime-help/#findComment-1027234 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.