Current location: Hot Scripts Forums » Programming Languages » PHP » list all dates - date range


list all dates - date range

Reply
  #1 (permalink)  
Old 11-12-04, 04:39 AM
lool49 lool49 is offline
Newbie Coder
 
Join Date: Nov 2003
Posts: 26
Thanks: 0
Thanked 0 Times in 0 Posts
Wink list all dates - date range

G'day

If someone could please help me...

I'm trying to find out a way where i can list all dates within a date range.

Like this:::

2004-10-02 to 2004-10-05 would display:

2004-10-02
2004-10-03
2004-10-04
2004-10-05

Any ideas?
By the way, the dates are in a db if it helps/matters...
Reply With Quote
  #2 (permalink)  
Old 11-12-04, 06:16 AM
<?Wille?> <?Wille?> is offline
Junior Code Guru
 
Join Date: Jan 2004
Location: Helsinki, Finland
Posts: 666
Thanks: 0
Thanked 0 Times in 0 Posts
something like
PHP Code:

 function ListDays ($startdate$enddate) {
   
$tmp[0] = split('-'$startdate);
   
$tmp[1] = split('-'$enddate);
   
$date mktime(000$tmp[0][1], $tmp[0][2], $tmp[0][0]);
   
$end mktime(000$tmp[1][1], $tmp[1][2], $tmp[1][0]);
   while (
$date <= $end) {
     echo 
date('Y-m-d').'<br />';
     
$date += (24*60*60);
   }
   return 
true;
 } 
its untested and might not be as fast as it could be but should list the dates
hope it helps
Wille
Reply With Quote
  #3 (permalink)  
Old 11-12-04, 07:25 AM
lool49 lool49 is offline
Newbie Coder
 
Join Date: Nov 2003
Posts: 26
Thanks: 0
Thanked 0 Times in 0 Posts
Big thanks

Thanks, it worked with a small mod! Thanks a lot would never have figured it out myself!

Here is the mod if anyone is looking for it


<?php
function ListDays ($startdate, $enddate) {
$tmp[0] = split('-',$startdate);
$tmp[1] = split('-',$enddate);
$date = mktime(0,0,0,$tmp[0][1], $tmp[0][2], $tmp[0][0]);
$end = mktime(0,0, 0, $tmp[1][1], $tmp[1][2], $tmp[1][0]);
while ($date <= $end) {
echo strftime("%Y-%m-%d",$date);
echo '<br />';
$date += (24*60*60);
}
return true;
}

?>
Reply With Quote
  #4 (permalink)  
Old 11-12-04, 07:53 AM
<?Wille?> <?Wille?> is offline
Junior Code Guru
 
Join Date: Jan 2004
Location: Helsinki, Finland
Posts: 666
Thanks: 0
Thanked 0 Times in 0 Posts
i did it again.. didnt think it to the end..
PHP Code:

    <?
    
function ListDays ($startdate$enddate) {
      
$tmp[0] = split('-',$startdate);
      
$tmp[1] = split('-',$enddate);
      
$date mktime(000$tmp[0][1], $tmp[0][2], $tmp[0][0]);
      
$end mktime(000$tmp[1][1], $tmp[1][2], $tmp[1][0]);
      while (
$date <= $end) {
      echo 
date('Y-m-d'$date).'<br />'# never used the $date variable witch resulted it to output today
         
$date += (24*60*60);
      }
      return 
true;
    } 
    
    
?>
glad you got it working tho
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
display all dates between two date dhzen JavaScript 0 07-21-04 11:53 PM
dates comperation jack ASP 2 05-11-04 03:25 AM
Problem with date and form djavet PHP 3 05-02-04 12:37 AM
hey need comparison of dates for reminder traceMe ASP 1 03-11-04 08:39 AM
Booking: Check availablility within a date range lool49 PHP 1 11-15-03 05:43 AM


All times are GMT -5. The time now is 05:13 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.