Connecting Tech Pros Worldwide Help | Site Map

How to get the days between two given dates (no sql stuff)

JAPIO
Guest
 
Posts: n/a
#1: Aug 23 '05
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.

Marcin Dobrucki
Guest
 
Posts: n/a
#2: Aug 23 '05

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
Alvaro G Vicario
Guest
 
Posts: n/a
#3: Aug 24 '05

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
--
Closed Thread


Similar PHP bytes