Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

Re: week of the year

by choroba (Cardinal)
on Aug 07, 2014 at 13:51 UTC ( [id://1096624]=note: print w/replies, xml ) Need Help??


in reply to week of the year

Using Time::Piece:
use Time::Piece; print 'Time::Piece'->strptime("080614", "%y%m%d")->week, "\n";

The output is 24, not 32, so I'm not sure it's the solution you were after.

Update: Using the %m%y%d format, you can get 33, which is almost the expected value. Maybe you are not using the ISO 8601 method to count the weeks? (At least the format of the date hints you don't.)

The week number may be an unknown concept to some readers. The ISO 8601 standard defines that weeks begin on a Monday and week 1 of the year is the week that includes both January 4th and the first Thursday of the year. In other words, if the first Monday of January is the 2nd, 3rd, or 4th, the preceding days of the January are part of the last week of the preceding year. Week numbers range from 1 to 53.

Using %m%d%y seems to return 32.

لսႽ† ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ

Replies are listed 'Best First'.
Re^2: week of the year
by Utilitarian (Vicar) on Aug 07, 2014 at 14:13 UTC
    I'm going to go ahead and assume that you meant today ;)
    utilitarian@busybox ~/$ perl -MTime::Piece -E 'say Time::Piece->strpti +me("080614", "%m%d%y")->week'; 32

    print "Good ",qw(night morning afternoon evening)[(localtime)[2]/6]," fellow monks."

      Hm, but in my timezone, today is 140807 ;]. Of course I would never put the d between the m and the y. Ever.


      Enjoy, Have FUN! H.Merijn
Re^2: week of the year
by BrowserUk (Patriarch) on Aug 07, 2014 at 13:58 UTC
    "%y%m%d"

    Should be "%d%m%y"?


    With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    "Science is about questioning the status quo. Questioning authority".
    In the absence of evidence, opinion is indistinguishable from prejudice.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others lurking in the Monastery: (4)
As of 2024-03-29 07:08 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found