Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Re^2: How to find first day of the first week on the month? ( strptime %Y-%j time-piece-firstlastofeverymonth.pl)

by Anonymous Monk
on Sep 28, 2013 at 23:42 UTC ( [id://1056171]=note: print w/replies, xml ) Need Help??


in reply to Re: How to find first day of the first week on the month?
in thread How to find first day of the first week on the month?

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
  • Comment on Re^2: How to find first day of the first week on the month? ( strptime %Y-%j time-piece-firstlastofeverymonth.pl)
  • Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1056171]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others rifling through the Monastery: (6)
As of 2024-04-10 20:54 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found