Jump to content

Quick Date strtotime() help.


iPixel

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.