The right way to do this is to parse it into a number of seconds as would be returned by time() and then to add the number of seconds in a day times the number of days you want, and then convert it back.
use Date::Parse; my $day = 24*60*60; my $x = 3; # set this. my $xdays = $x * $day; print scalar localtime(str2time("20121231") + $xdays);
Update: Changed to produce the requested format and to use the given example. Apparently I have too much time on my hands.
use Date::Parse; my $date = "20120516"; my $day = 24*60*60; my $x = 24; # set this. my $xdays = $x * $day; # see perldoc -f localtime. my @t = (localtime(str2time($date) + $xdays))[5,4,3]; $t[0] += 1900; # localtime returns years since 1900. $t[1] += 1; # localtime returns month in range 0..11. printf "%04d%02d%02d\n", @t;
In reply to Re: Adding Days To YYYYMMDD Date Format
by sauoq
in thread Adding Days To YYYYMMDD Date Format
by Zoomie
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |