Perl script - add days to Date to get new date

date, perl

Solution

Convert $date from the input format to the old format:

$date =~ s%(....)(..)(..)%$3/$2/$1%;

If the output format should not be `%m/%d/%Y`, then do not set it to it. You obviously need `%Y%m%d`.

Problem

I am working on a perl script to add days to a date and display the newdate: ``` use Time::ParseDate; use Time::CTime; my $date = "02/01/2003"; my $numdays = 30; my $time = parsedate($date); # add $numdays worth of seconds my $newtime = $time + ($numdays * 24 * 60 * 60); my $newdate = strftime("%m/%d/%Y",localtime($newtime)); print "$newdate\n"; The output will be: 03/03/2003 ``` Now how do I set the input for the date field to be yyyymmdd Ex: my $date = "20030102" Also the output will need to be : 20030303 Thanks

Original source