How To Calculate Time In Perl Using Date::Manip OO Mode

Published Date Author: , Posted March 22nd, 2011 at 7:19:48pm


my $now = new Date::Manip::Date;
$now->parse('now'); # in GMT
$now->convert('EST5EDT'); # in Eastern time

my $then = new Date::Manip::Date;
$then->parse('200503131131'); # in GMT
$then->convert('EST5EDT'); # in Eastern time

my $delta = $now->calc($then);
my @delta = $delta->value(); # get delta values as an array
foreach (@delta) { $_ = abs($_); } # remove negative signs

my $years = abs(int($delta[2]/52));
my $weeks = abs($delta[2]) - abs($years*52);

print 'As of ', $now->printf('%A, %B %E, %Y at%i:%M %p'), ", we have been happily married for $years years, $weeks weeks, $delta[3] days, $delta[4] hours and $delta[5] minutes!";

No comments as yet.

Leave Your Comment  Leave a comment

All fields marked with "*" are required.