[OPEN-ILS-DEV] DateTime::Format::Duration

Victoria Lewis vLewis at catalystitservices.com
Fri Jun 5 15:02:42 EDT 2015


Hello,

I want to find the difference in days between two dates.

#This parses out the date fields from the timestamp string retrieved from database
my ($year, $month, $day, $hour, $minute, $second, $tz) = $row[0] =~ /^([0-9]{4})-([0-9]{2})-([0-9]{2})\s([0-9]{2}):([0-9]{2}):([0-9]{2})-([0-9]{2})\z/;

my $last_date_entered = DateTime->new(
    year        => $year,
    month       => $month,
    day         => $day,
    hour        => $hour,
    minute      => $minute,
    second      => $second,
    time_zone       => 'local',
);

#Calculate the number of missed days, if any, between the current run date and the last run date
my $date = DateTime->now->subtract(days => 1);
my $duration = $date->delta_days($last_date_entered);
my $format = DateTime::Format::Duration->new(
    pattern => ' %e'  # just the days
);
my $day_diff = $format->format_duration($duration);

I installed DateTime::Format::Duration
Is there an existing library in Evergreen that does the same thing?
Thanks.
Victoria Lewis


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://libmail.georgialibraries.org/pipermail/open-ils-dev/attachments/20150605/0d25efce/attachment.html>


More information about the Open-ils-dev mailing list