Jump to content


 


Register a free account to unlock additional features at BleepingComputer.com
Welcome to BleepingComputer, a free community where people like yourself come together to discuss and learn how to use their computers. Using the site is easy and fun. As a guest, you can browse and view the various discussions in the forums, but can not create a new topic or reply to an existing one unless you are logged in. Other benefits of registering an account are subscribing to topics and forums, creating a blog, and having no ads shown anywhere on the site.


Click here to Register a free account now! or read our Welcome Guide to learn how to use this site.

Photo

adding a week to a date (PHP)


  • Please log in to reply
1 reply to this topic

#1 KamakaZ

KamakaZ

  • Members
  • 739 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:Victoria
  • Local time:03:02 AM

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'));

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.


BC AdBot (Login to Remove)

 


#2 groovicus

groovicus

  • Security Colleague
  • 9,963 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:Centerville, SD
  • Local time:10:02 AM

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>





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users