Jump to content

Recommended Posts

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!

Link to comment
https://forums.phpfreaks.com/topic/195475-quick-date-strtotime-help/
Share on other sites

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.

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);
}
?>

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.