Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

calculate inbetween dates

Status
Not open for further replies.

dodgyone

Technical User
Jan 26, 2001
431
GB
I want to be able to display the dates inbetween and including the from and to dates given.

[So]...

From: 13/04/2002 To: 17/04/2002...

[This will result in]...

13/04/2002
14/04/2002
15/04/2002
16/04/2002
17/04/2002

I then need each date to be piped into an array so that it can be used later...

Any ideas or suggestions appreciated.
 
Do you have the Calendar functions enabled (i.e. was PHP compiled with the --enable-calendar)?

If so, you can convert both dates to Julian Day counts using the function gregoriantojd(), then use the resulting numbers as the bounds of a counter in a loop;

<?php
print &quot;<html><body>&quot;;

$start = &quot;13/04/2002&quot;;
$end = &quot;17/4/2002&quot;;

$start_array = split (&quot;/&quot;, $start);
$end_array = split (&quot;/&quot;, $end);

$julian_start = gregoriantojd ($start_array[1], $start_array[0], $start_array[2]);
$julian_end = gregoriantojd ($end_array[1], $end_array[0], $end_array[2]);

for ($count = $julian_start; $count <= $julian_end; $count++)
{
print jdtogregorian($count).&quot;<br>&quot;;
}

print &quot;</body></html>&quot;;
?>

 
Unfortunately we do not have all of the calendar functions enable don the server. I don't have access to the server to be able to change these settings.

Do you have any more suggestions?

Thanks...
 
I'm now working around using the folowing idea:

#count the number of days involved between the dates
$numberdays = $dateto - $datefrom;

#create an array with all of the dates inbetween from and to
for ($i=0; $i<=$numberdays; $i++)
{

#calculates the date in the recurrence
echo date(&quot;Y-m-d&quot;, mktime(0,0,0,$monthfrom,$dayfrom+$i-date(&quot;w&quot;,mktime(0,0,0,$monthfrom,$dayfrom,$yearfrom)),$yearfrom));
echo &quot;<br>&quot;;
}

I'm heading in the right direction but I cannot quite get it to work correctly...
 
this might help you:

<?php



$month = date(&quot;m&quot;);
$day = date(&quot;d&quot;);
$year = date(&quot;Y&quot;);

echo &quot;Today is $day $month $year<hr>&quot;;
echo &quot;This week:<br>&quot;;
echo &quot;Monday: &quot;.date(&quot;d m Y&quot;, mktime(0,0,0,$month,$day+1-date(&quot;w&quot;,mktime(0,0,0,$month,$day,$year)),$year)).&quot;<br>&quot;;
echo &quot;Friday: &quot;.date(&quot;d m Y&quot;, mktime(0,0,0,$month,$day+5-date(&quot;w&quot;,mktime(0,0,0,$month,$day,$year)),$year)).&quot;<br>&quot;;
echo &quot;<hr>&quot;;

echo &quot;Next week:<br>&quot;;
echo &quot;Monday is : &quot;.date(&quot;d m Y&quot;, mktime(0,0,0,$month,$day+8-date(&quot;w&quot;,mktime(0,0,0,$month,$day,$year)),$year)).&quot;<br>&quot;;
echo &quot;Friday is : &quot;.date(&quot;d m Y&quot;, mktime(0,0,0,$month,$day+12-date(&quot;w&quot;,mktime(0,0,0,$month,$day,$year)),$year)).&quot;<br>&quot;;

?> ***************************************
Party on, dudes!
[cannon]
 
a simple solution

for($i=0;($time=mktime(0,0,0,$begin_mon,$begin_day+$i,$begin_year))<=mktime(0,0,0,$end_mon,$end_day,$end_year);$i++){
echo date(&quot;d-m-Y&quot;,$time).&quot;<br>&quot;;
}
Anikin
Hugo Alexandre Dias
Web-Programmer
anikin_jedi@hotmail.com
 
Anikin I follow your example and post hints and code that points in the right direction and you go and post a complete spoiler :) ***************************************
Party on, dudes!
[cannon]
 
the complete code would be:

list($begin_day,$begin_mon,$begin_year)=explode(&quot;-&quot;,$begin);
list($end_day,$end_mon,$end_year)=explode(&quot;-&quot;,$end);


for($i=0;($time=mktime(0,0,0,$begin_mon,$begin_day+$i,$begin_year))<=mktime(0,0,0,$end_mon,$end_day,$end_year);$i++){
echo date(&quot;d-m-Y&quot;,$time).&quot;<br>&quot;;
}


Anikin
Hugo Alexandre Dias
Web-Programmer
anikin_jedi@hotmail.com
 
Thanks Karver... I got it from your examples.

I prefer your way of doing things... I prefer to learn from my mistakes ;o)
 
Status
Not open for further replies.

Similar threads

Part and Inventory Search

Sponsor

Back
Top