Doing day math with %j which is day of year (yday)

#!/usr/bin/perl -- ## perltidy -olq -csc -csci=10 -cscl="sub : BEGIN END" -otr -opr -ce +-nibc -i=4 -pt=0 "-nsak=*" use strict; use warnings; use Time::Piece; my $now = localtime; my $year = shift || $now->year; for my $mon ( 1 .. 12 ) { my $first = Time::Piece->strptime( qq/$year-$mon/, q/%Y-%m/ ); my $mon = $first->mon; my $yday = $first->yday; my( $last ) = grep { $_->mon == $mon } map { Time::Piece->strptime( qq/$year-$_/, q/%Y-%j/ ) } map { $yday + $_ } reverse 28 .. 31; printf '%4d %3s %02d/%02d-%02d/%02d ', $first->year, $first->month, $first->mon, $first->mday, $last->mon, $last->mday,; print "\n" if 0 == $mon % 3; } __END__ 2013 Jan 01/01-01/31 2013 Feb 02/01-02/28 2013 Mar 03/01-03/31 2013 Apr 04/01-04/30 2013 May 05/01-05/31 2013 Jun 06/01-06/30 2013 Jul 07/01-07/31 2013 Aug 08/01-08/31 2013 Sep 09/01-09/30 2013 Oct 10/01-10/31 2013 Nov 11/01-11/30 2013 Dec 12/01-12/31

In reply to Re^2: How to find first day of the first week on the month? ( strptime %Y-%j time-piece-firstlastofeverymonth.pl) by Anonymous Monk
in thread How to find first day of the first week on the month? by devbond

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.