How to find the previous date for a given date as Aug 17 in perl. I am able to get the current date in perl by using the below code. Can some-one help me to find the previous date for a given date.
Given date as : Aug 17
Required Date as : Aug 16
#Reverting the Date for the respective TimeZone
my $timezone='london';
my ($dt, $Curr_Bus_Date,$Curr_day);
$dt = DateTime->now(time_zone => $timezone);
$Curr_mon=$dt->strftime('%b');
$Curr_date=$dt->strftime('%d');
$Curr_date=~s/^0/ /;
$Curr_dt="$Curr_mon $Curr_date ";
print "The curr date is $Curr_dt \n";
The DateTime class has a
subtract()method. It’s clearly documented.You can also do it with Perl’s standard (since 5.10) Time::Piece and Time::Seconds classes.
With both of those approaches you should bear in mind that subtracting one day from the current date won’t always get you to the previous day.