Help, im a newb (something with dates)

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
chadbobb
Forum Newbie
Posts: 8
Joined: Mon Nov 08, 2004 8:27 pm

Help, im a newb (something with dates)

Post by chadbobb »

I want display the date of today and 15 days into the future

Code: Select all

<?php
$d=date(" d ");

do
&#123;
$d++;
echo $d . "<br>";
&#125;
while ($d<15);
?>
That is what i came up with, with the very little i know about php, but i cant get it to work it just gives todays day. And php.net hasn't help me at all with the manual, and nothing else. So i figured to just ask a person.
User avatar
Slippy
Forum Contributor
Posts: 113
Joined: Sat Jul 12, 2003 11:31 pm
Location: Vancouver eh!

Post by Slippy »

From a comment in the php manual:

Code: Select all

<?php
  $time = mktime(0,0,0,1,31,2005);
  $newtime = strtotime('+1 month', $time);
  echo 'One month after ' . date('m/d/Y', $time) . ' is ' . date('m/d/Y', $newtime);
  // One month after 01/31/2005 is 03/03/2005
?>
Just add 15 days instead...
chadbobb
Forum Newbie
Posts: 8
Joined: Mon Nov 08, 2004 8:27 pm

Post by chadbobb »

Im sorry i messed up in my original descriptinon. I also want it to list all the days in between today and the next 15 days.

thanks for helping though.

how would i go about having it show each day.
User avatar
neophyte
DevNet Resident
Posts: 1537
Joined: Tue Jan 20, 2004 4:58 pm
Location: Minnesota

Days into the future...

Post by neophyte »

How bout this script:

Code: Select all

<?php
function futureday($num_days_future)
{
	for ($x=0; $x<$num_days_future; $x++)// loop through and add one day in seconds each time...
	{
 		$numsec = 86400 * $x; //Multiply seconds by num_days_future
 		$nextday = time()+ $numsec; //Get Unix Time stamp
 		 
		echo date("j of F Y, h:m a", $nextday)."<br>";	
	}
}

futureday(15);

?>
Echo's something like...

Code: Select all

9 of November 2004, 11:11 pm
10 of November 2004, 11:11 pm
11 of November 2004, 11:11 pm
12 of November 2004, 11:11 pm
13 of November 2004, 11:11 pm
14 of November 2004, 11:11 pm
15 of November 2004, 11:11 pm
16 of November 2004, 11:11 pm
17 of November 2004, 11:11 pm
18 of November 2004, 11:11 pm
19 of November 2004, 11:11 pm
20 of November 2004, 11:11 pm
21 of November 2004, 11:11 pm
22 of November 2004, 11:11 pm
23 of November 2004, 11:11 pm
chadbobb
Forum Newbie
Posts: 8
Joined: Mon Nov 08, 2004 8:27 pm

Post by chadbobb »

I think that will do it. Thanks a bunch.

BTW is your name jacob?
User avatar
neophyte
DevNet Resident
Posts: 1537
Joined: Tue Jan 20, 2004 4:58 pm
Location: Minnesota

Not Jacob

Post by neophyte »

Nope -- sorry.
chadbobb
Forum Newbie
Posts: 8
Joined: Mon Nov 08, 2004 8:27 pm

Post by chadbobb »

thats fine.

I should probably ask about what you did for that script, that way i can learn from it. I see what you did for most of it. But why did you have to this ?

Code: Select all

$numsec = 86400 * $x; //Multiply seconds by num_days_future
User avatar
neophyte
DevNet Resident
Posts: 1537
Joined: Tue Jan 20, 2004 4:58 pm
Location: Minnesota

Post by neophyte »

There are 86400 seconds per day. Time() returns the number of seconds since the Unix Epoch. So by adding 86400*$x or the number of days into the future you get that day's date by formating that number of seconds with the date() function.

Code: Select all

<?php
$numsec = 86400 * $x; //Multiply seconds by num_days_future
?>
Post Reply