G'day viffer,

You can do all those date calculations with the built-in modules Time::Piece and Time::Seconds.

Here are examples of the types of things you indicated. Do check the doco: there may be other ways to do these which more closely fit your requirements.

$ perl -Mstrict -Mwarnings -E ' use Time::Piece; use Time::Seconds; my @ordinals = qw{1st 2nd 3rd 4th 5th}; my @even_odd = qw{even odd}; my $secs_per_week = 7 * 24 * 60 * 60; my $days_from_now = 15; my $now = localtime; say "Today is: ", $now->strftime; if ($now->fullday eq "Tuesday") { say "It is the $ordinals[$now->mday / 7] Tuesday of the month. +"; say "It is the ", int($now->epoch / $secs_per_week), "th Tuesday of the +epoch."; say "So it is an $even_odd[$now->epoch / $secs_per_week % 2] T +uesday."; } else { say "Not Tuesday: nothing to do."; } my $future = $now + ONE_DAY * $days_from_now; say "$days_from_now days from now will be: ", $future->strftime; say "That is ", $future->wdayname =~ /^(?:Sat|Sun)$/ ? "" : "not ", "a wee +kend."; ' Today is: Tue, 17 Sep 2013 11:38:22 EST It is the 3rd Tuesday of the month. It is the 2280th Tuesday of the epoch. So it is an even Tuesday. 15 days from now will be: Wed, 02 Oct 2013 11:38:22 EST That is not a weekend.

-- Ken


In reply to Re: Dates - which Tuesday is it by kcott
in thread Dates - which Tuesday is it by viffer

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.