Page 1 of 1

Help, im a newb (something with dates)

Posted: Mon Nov 08, 2004 8:30 pm
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.

Posted: Mon Nov 08, 2004 9:50 pm
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...

Posted: Tue Nov 09, 2004 9:23 pm
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.

Days into the future...

Posted: Tue Nov 09, 2004 10:21 pm
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

Posted: Tue Nov 09, 2004 10:42 pm
by chadbobb
I think that will do it. Thanks a bunch.

BTW is your name jacob?

Not Jacob

Posted: Tue Nov 09, 2004 10:45 pm
by neophyte
Nope -- sorry.

Posted: Tue Nov 09, 2004 10:52 pm
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

Posted: Wed Nov 10, 2004 8:05 am
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
?>