Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses

ISO Date Week Number

by Anonymous Monk
on Sep 06, 2005 at 06:54 UTC ( #489374=perlquestion: print w/replies, xml ) Need Help??
Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:


Assuming that I am forced to work under Perl 5.0 (the sysadmins wont upgrade), and that I am not able to install any modules, is there a pure Perl way to work out the ISO week number from any given date in the format DD/MM/YYYY. The date will be from user input.


Replies are listed 'Best First'.
Re: ISO Date Week Number
by mattk (Pilgrim) on Sep 06, 2005 at 07:44 UTC
    This is assuming your install of v5.0 has a working
    use POSIX 'strftime'; # replace with actual date my @localtime = qw/YYYY MM DD 00 00 00/; # see perldoc -f localtime $localtime[0] -= 1900; $localtime[1] -= 1; print strftime('%V', reverse @localtime);
      From my copy of (perldoc POSIX):
      If you want your code to be portable, your format ("fmt") argument should use only the conversion specifiers defined by the ANSI C standard. These are "aAbBcdHIjmMpSUwWxXyYZ%".
      I'm not familiar with the apparently non-standard %V code. Does that offer the "week number" as requested by the original poster? On what platform(s)?

      [ e d @ h a l l e y . c c ]

        Yes, it corresponds to ISO's standard definition of a week number.

        Tested on:
        Linux 2.4.21, Perl v5.6.1
        Linux 2.6.10, Perl v5.8.3
        Mac OS X Tiger 10.4.2, Perl v5.8.6

        Of course, if the OP is still using v5.0 I've got no idea what kind of old OS they're using, so YMMV.
Re: ISO Date Week Number
by svenXY (Deacon) on Sep 06, 2005 at 07:39 UTC

    I can see at least two possible ways here:
    1. some code I found by googling:
    2. Install modules somewhere, where you have write access, for example in your homedirectory or somewhere else. You then just need to tell your Perl program where to find those modules: hth,
Re: ISO Date Week Number
by Anonymous Monk on Sep 06, 2005 at 07:11 UTC

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://489374]
Approved by holli
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (4)
As of 2018-06-20 01:05 GMT
Find Nodes?
    Voting Booth?
    Should cpanminus be part of the standard Perl release?

    Results (116 votes). Check out past polls.