On Thu, 10 Jun 2004, Matt Sisk wrote:

> What I'd like to do is simply find the midpoint, more or less, between
> two arbitrary datetimes. Off the cuff, knowing nothing about the
> internals (which I do, but I'm pretending not to) I'd think this:
>
>   $mid = $dt1 + ($dt2 - $dt1)/2
>
> to dwim.
>
> However, as you say, things aren't really well defined the way durations
> are defined internally at the moment.
>
> So the question becomes -- if the above is not the datetime idiom for
> finding a midpoint between two datetimes, then what is?

Well, if you just want the _date_, it's pretty easy.

 my $dur = $dt1->delta_days($dt2);

 # or use Math::Round if you want
 my $mid = $dt1->add( days => int( $dur->delta_days / 2 ) );

If you want to account for the time then it gets funkier.


-dave

/*=======================
House Absolute Consulting
www.houseabsolute.com
=======================*/

Reply via email to