BleepingComputer.com: adding a week to a date (PHP)

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

adding a week to a date (PHP)

#1 User is offline   KamakaZ 

  • Senior Member
  • PipPipPipPip
  • Find Topics
  • Group: Members
  • Posts: 557
  • Joined: 26-August 08
  • Gender:Male
  • Location:Victoria

  Posted 05 October 2009 - 12:36 AM

Ok, so i've done loads of searching and tried various ways to add a week to a date, this is what i have got.

<?php


$now = date('d/m/Y');
$nextWeek = date('d/m/Y', strtotime('+1 week'));
$monday = date('d/m/Y', strtotime("next monday"));
$tuesday = date('d/m/Y', strtotime("next tuesday"));
$wednesday = date('d/m/Y', strtotime("next wednesday"));
$thursday = date('d/m/Y', strtotime("next thursday"));
$friday = date('d/m/Y', strtotime("next friday"));
$saturday = date('d/m/Y', strtotime("next saturday"));
$sunday = date('d/m/Y', strtotime("next sunday"));

if ($nextWeek > $monday) {

$monday = date('d/m/Y', strtotime("next monday", '+1 week'));
}

if ($nextWeek > $tuesday) {

$tuesday = date('d/m/Y', strtotime("next tuesday", '+1 week'));
}

if ($nextWeek > $wednesday) {

$wednesday = date('d/m/Y', strtotime("next wednesday", '+1 week'));
}

if ($nextWeek > $thursday) {

$thursday = date('d/m/Y', strtotime("next thursday", '+1 week'));
}

if ($nextWeek > $friday) {

$friday = date('d/m/Y', strtotime("next friday", '+1 week'));
}

if ($nextWeek > $saturday) {

$saturday = date('d/m/Y', strtotime("next saturday", '+1 week'));
}

if ($nextWeek > $sunday) {

$sunday = date('d/m/Y', strtotime("next sunday", '+1 week'));
}

echo "<br />";
echo "Today: " . $now;
echo "<br />";
echo "Next Week: " . $nextWeek;
echo "<br />";
echo "Monday: " . $monday;
echo "<br />";
echo "Tuesday: " . $tuesday;
echo "<br />";
echo "Wednesday: " . $wednesday;
echo "<br />";
echo "Thursday: " . $thursday;
echo "<br />";
echo "Friday: " . $friday;
echo "<br />";
echo "Saturday: " . $saturday;
echo "<br />";
echo "Sunday: " . $sunday;
echo "<br />";
?>


I'm trying to obtain next weeks dates. I have got it down to this bit of code not functioning right, even though it is published this exact way in multiple tutorials.

 
$sunday = date('d/m/Y', strtotime("next sunday", '+1 week'));

If I am helping you and don't reply in 24 hours please send me a PM

There's no place like 127.0.0.1
There are 10 types of people in the world, those that can read binary, and those who can't.

#2 User is offline   groovicus 

  • Hail Groovicus!
  • PipPipPipPipPipPip
  • Find Topics
  • Group: Moderator
  • Posts: 9,604
  • Joined: 05-June 04
  • Gender:Male
  • Location:Centerville, SD

Posted 07 October 2009 - 08:39 PM

It is much easier than that:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">

<head>
	
	
</head>

<body>
	<?php
		$today = getdate();
		$nextWeek = mktime(0, 0, 0, date("m"), date("d")+7, date("y"));
		echo("Today is: " . date("l m/d/y") . ".................A week from today is : " . date("l m/d/y",$nextWeek));	
	?> 
	
</body>

</html>

"Take the risk of thinking for yourself, much more happiness, truth, beauty, and wisdom will come to you that way" - Christopher Hitchens

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users