Help | Site Map
Connecting Tech Pros Worldwide
 
 
LinkBack Thread Tools
  #1  
Old August 23rd, 2005, 11:15 AM
JAPIO
Guest
 
Posts: n/a
Default How to get the days between two given dates (no sql stuff)

I have two variables which look like:
$begin = "23-08-05"
$end = "26-08-05"

Now i want also to know the dates between them.
24-08-05
25-08-05

How can i do this? Any help would be appreciated.

  #2  
Old August 23rd, 2005, 11:35 AM
Marcin Dobrucki
Guest
 
Posts: n/a
Default Re: How to get the days between two given dates (no sql stuff)

JAPIO wrote:[color=blue]
> I have two variables which look like:
> $begin = "23-08-05"
> $end = "26-08-05"
>
> Now i want also to know the dates between them.
> 24-08-05
> 25-08-05
>
> How can i do this? Any help would be appreciated.[/color]

(hope this is not some course homework...)

list ($day, $month, $year) = split('-', $date);
$t = mktime(0,0,0,$day,$month,$year+2000)

So now you have start/end. Then:

while ($start < $end) {
do_whatever();
$start += 86400;
}

And you can use date() to convert the timestamp back to
human-readable format.

/Marcin
  #3  
Old August 24th, 2005, 01:15 PM
Alvaro G Vicario
Guest
 
Posts: n/a
Default Re: How to get the days between two given dates (no sql stuff)

*** JAPIO wrote/escribió (23 Aug 2005 03:08:45 -0700):[color=blue]
> I have two variables which look like:
> $begin = "23-08-05"
> $end = "26-08-05"
>
> Now i want also to know the dates between them.
> 24-08-05
> 25-08-05[/color]

Days or dates?

For days (not tested):

<?

$begin = "23-08-05";
$end = "26-08-05";

echo ceil( (strtotime($end)-strtotime($begin)) / 86400 );

?>

I not sure though whether strtotime() works with European format.

--
-- Álvaro G. Vicario - Burgos, Spain
-- http://bits.demogracia.com - Mi sitio sobre programación web
-- Don't e-mail me your questions, post them to the group
--
 

Bookmarks

Thread Tools

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 Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over network members.
Post your question now . . .
It's fast and it's free

Popular Articles