use 5.014; use DateTime qw(); my %day2t = ( Friday => 'T', Saturday => 'T-1', Sunday => 'T-2', Monday => 'T-3', Tuesday => 'T-4', Wednesday => 'T-5', Thursday => 'T-6', ); { my $today = DateTime->now->truncate(to => 'day'); # 2013-11-25T00: +00:00 $today->day_name; # Monday $day2t{$today->day_name}; # T-3 my $into_the_past = ($day2t{$today->day_name} =~ s/T-?//r) || 0; # + 3 $today->clone->subtract(days => $into_the_past)->strftime('%F'); # + 2013-11-22 } { my $beginning_of_november = DateTime->new(year => 2013, month => 1 +1, day => 1); # 2013-11-01T00:00:00 $beginning_of_november->day_name; # Friday $day2t{$beginning_of_november->day_name}; # T my $into_the_past = ($day2t{$beginning_of_november->day_name} =~ s +/T-?//r) || 0; # 0 $beginning_of_november->clone->subtract(days => $into_the_past)->s +trftime('%F'); # 2013-11-01 }

In reply to Re: Setting up date to subtract specific number from it by daxim
in thread Setting up date to subtract specific number from it by vihar

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • 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:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.