Days between two dates

Paul Makepeace london.pm.org at paulm.com
Thu Dec 22 15:10:24 GMT 2005


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
 $

Paul


-- 
Paul Makepeace .............................. http://paulm.com/inchoate/

"What is the word for octopus in polari? Swim and talk."
   -- http://paulm.com/toys/surrealism/


More information about the london.pm mailing list