Days between two dates

Jonathan Stowe jns at gellyfish.com
Thu Dec 22 15:55:01 GMT 2005


On Thu, 2005-12-22 at 15:25, Delfim Machado wrote:
> On Dec 22, 2005, at 15:10, Paul Makepeace wrote:
> 
> > A should-be-obvious question. How does one find the number of days
> > between two dates, without converting to epoch? (so I can do while
> > --$days >= 0) I thought ($end_dt - $start_dt)->in_units('days')  
> > would do
> > it but if the ::Duration ends up with a 'month' figure data is  
> > effectively
> > lost (which month? i.e. how long?) and then you can't convert to days.
> >
> > Here's an example where there's a definite answer but DateTime loses
> > info by having its ::Duration use months:
> >
> >  $ perl -MDateTime -le '
> >      $s=DateTime->new(year => 2005, month => 10, day => 1);
> >      $d=DateTime->new(year => 2005, month => 12, day => 1);
> >      print(($d-$s)->in_units("days"))'
> > 0
> >  $
>
> you can use Date::Calc qw(Date_to_Days).
> 

I would guess that the Delta_* functions from Date::Calc are nearer the
mark.

/J\

-- 

This e-mail is sponsored by http://www.integration-house.com/



More information about the london.pm mailing list