[me ~]$ perl datefail.pl --startday='-15 days' --endday='-14 days' Start with Today 20151120T22:51-0700 Fix timezone 20151120T21:51-0800 Set the right day 20151105T21:51-0800 Strip the hours 20151105T00:51-0800 Strip the minutes 20151105T00:00-0800 [me ~]$ perl datefail.pl --startday='-19 days' --endday='-18 days' Start with Today 20151120T22:51-0700 Fix timezone 20151120T21:51-0800 Set the right day 20151101T21:51-0800 Strip the hours 20151101T01:51-0700 Strip the minutes 20151101T01:00-0700 #### #!/usr/bin/perl use strict; use warnings; use Date::Manip; use Getopt::Long qw(GetOptions); my $startDay; my $endDay; GetOptions( 'startday=s' => \$startDay ,'endday=s' => \$endDay ); my ( $startDDelta,$zeroStartH,$zeroStartHDelta,$zeroStartM,$zeroStartMDelta ); print "Start with Today\n"; my $dateObjStart = new Date::Manip::Date('now'); print $dateObjStart->printf('%Y%m%dT%H:%M%z') . "\n"; print "Fix timezone\n"; $dateObjStart->convert('US/Pacific'); print $dateObjStart->printf('%Y%m%dT%H:%M%z') . "\n"; print "Set the right day\n"; $startDDelta = new Date::Manip::Delta($startDay); $dateObjStart = $dateObjStart->calc($startDDelta); print $dateObjStart->printf('%Y%m%dT%H:%M%z') . "\n"; print "Strip the hours\n"; $zeroStartH = '-'.$dateObjStart->printf('%H').' hours'; $zeroStartHDelta = new Date::Manip::Delta($zeroStartH); $dateObjStart = $dateObjStart->calc($zeroStartHDelta); print $dateObjStart->printf('%Y%m%dT%H:%M%z') . "\n"; print "Strip the minutes\n"; $zeroStartM = '-'.$dateObjStart->printf('%M').' minutes'; $zeroStartMDelta = new Date::Manip::Delta($zeroStartM); $dateObjStart = $dateObjStart->calc($zeroStartMDelta); print $dateObjStart->printf('%Y%m%dT%H:%M%z') . "\n";