G'day vihar,
You can do this very easily with the builtin modules Time::Piece and Time::Seconds.
Here's an example using Sunday, 1-Dec-2013 which, using your figures, should have 2 days subtracted; resulting in Friday, 29-Nov-2013.
#!/usr/bin/env perl -l
use strict;
use warnings;
use Time::Piece;
use Time::Seconds;
my %day2t = qw{Fri 0 Sat 1 Sun 2 Mon 3 Tue 4 Wed 5 Thu 6};
my $test_date = '1-Dec-2013';
my $t_now = Time::Piece->strptime($test_date, '%d-%b-%Y');
my $t_mod = $t_now - ONE_DAY * $day2t{$t_now->day};
print 'Time now: ', $t_now->strftime;
print 'Time modified: ', $t_mod->strftime;
Output:
Time now: Sun, 01 Dec 2013 00:00:00 UTC
Time modified: Fri, 29 Nov 2013 00:00:00 UTC
Notes:
-
I've used abbreviations for the day names.
If you need the full names, use the fullday() method instead of the day() method.
-
I've reduced your T and T-n values to simple digits.
If you need the forms you originally posted, you'll have to add some additional code.
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.