how to know the week of today?

Ask a Question related to PERL Miscellaneous, Design and Development.

  1. #1

    Default Re: how to know the week of today?

    "C&J" <ggkuo@yahoo.com> writes:
    > Is there any way to know what is the current week?
    POSIX::strftime supports at least one of the widely used "week number"
    algorithms, more on some platforms. (Note that the ISO and POSIX
    standards do not agree).
    > January 1 is the first week.
    That alone does not uniquely define your week number algorithm.

    You have to consider when week 2 starts. Does it always start on
    January 8 or does it start on the the first Fooday on or after January
    2.

    Anyhow, whatever your chosen algorithm (within reason) it can be
    expressed as a trivial integer expression in terms of $wday and $yday
    as retuned by localtime().

    If that feels too low-level for you then see Date::* on CPAN.

    --
    \\ ( )
    . _\\__[oo
    .__/ \\ /\@
    . l___\\
    # ll l\\
    ###LL LL\\
    Brian McCauley Guest

  2. Similar Questions and Discussions

    1. count for today, week, month totals
      does anyone know how to do a count for getting totals for today, week, month. Example. i submit a job request form. i need to know running totals...
    2. ASP.NET: Day / Work Week / Week / Month web calendar control with view like MS Outlook
      Hi!! Did Infragistics or some other company else provide a web calendar conrol with the features and look of Microsoft Outlook calendar? I mean...
    3. Since today is October 31...
      srand 0 puts "pH p!aoHalnyweel".split("").sort {|x,y| rand <=> rand }.join Cheers, Hal(loween)9000
    4. [DVD burner] Which one to buy today?
      I am thinking about buying an external firewire DVD burner for my G4 iMac 700mhz, 512MB ram. Which one would be today the best one, e.g. the most...
    5. Yep, definitely new hardware today
      Lawrence DčOliveiro wrote: Yup. When I get my G5, I'm deleting the OS X partition from my G4 and it'll be OS 9 only.
  3. #2

    Default Re: how to know the week of today?



    $thisday = (Sun,Mon,Tue,Wed,Thu,Fri,Sat)[(localtime)[6]];



    C&J wrote:
    >Hi,
    >Is there any way to know what is the current week?
    >January 1 is the first week.
    >Thanks
    >Chris
    >
    >
    >
    >
    --
    Regards,
    Dov Levenglick



    DOV LEVENGLICK Guest

  4. #3

    Default Re: how to know the week of today?

    DOV LEVENGLICK wrote:
    > C&J wrote:
    >>Is there any way to know what is the current week?
    >>January 1 is the first week.
    >
    > $thisday = (Sun,Mon,Tue,Wed,Thu,Fri,Sat)[(localtime)[6]];
    Err.. How is that solution related to OP's question?

    --
    Gunnar Hjalmarsson
    Email: [url]http://www.gunnar.cc/cgi-bin/contact.pl[/url]

    Gunnar Hjalmarsson Guest

  5. #4

    Default Re: how to know the week of today?

    Gunnar Hjalmarsson <noreply@gunnar.cc> writes:
    > DOV LEVENGLICK wrote:
    >> C&J wrote:
    >>>Is there any way to know what is the current week?
    >>>January 1 is the first week.
    >> $thisday = (Sun,Mon,Tue,Wed,Thu,Fri,Sat)[(localtime)[6]];
    >
    > Err.. How is that solution related to OP's question?
    Not at all, AFAICT, but the solution is in localtime():

    $weeknum = int((localtime)[7] / 7);

    -=Eric
    --
    Come to think of it, there are already a million monkeys on a million
    typewriters, and Usenet is NOTHING like Shakespeare.
    -- Blair Houghton.
    Eric Schwartz Guest

  6. #5

    Default Re: how to know the week of today?

    In article <etor846a9fv.fsf@wormtongue.emschwar>, Eric Schwartz
    <emschwar@ldl.fc.hp.com> wrote:
    > $weeknum = int((localtime)[7] / 7);
    Isn't that inaccurate?
    int( 365 / 7 ) = 52

    The 365th day of the year ( and on leap years, the 366th also) are in
    the 53rd week..

    The OP might want to check CPAN for any number of Date manipulation
    modules. 'The Perl Cookbook'[1] suggests Date::Calc.

    [bash:~]user% perl -e 'use Date::Calc qw(Week_Number);\
    print Week_Number('2003', 12, 31), "\n";'

    outputs: 53


    [1] pp 79 - 80.

    --
    cp
    cp Guest

  7. #6

    Default Re: how to know the week of today?

    "C&J" <ggkuo@yahoo.com> wrote in message news:<OWlVa.662$Qb7.504188001@newssvr12.news.prodi gy.com>...
    > Hi,
    > Is there any way to know what is the current week?
    > January 1 is the first week.
    > Thanks
    > Chris
    ## This may be helpful to you. Good luck. --JR

    #!/Perl
    use strict;
    use warnings;
    BEGIN {
    eval "use diagnostics";
    warn "Can't load diagnostics module.\n\n" if $@;
    }

    ## This assumes a seven day week, and that the first day
    ## of the year is January 1, xxxx.
    printf "This is week %d, of the year %d.", (localtime)[7]/7,
    (localtime)[5]+1900;
    JR Guest

  8. #7

    Default Re: how to know the week of today?

    cp <cpryce@pryce.nospam.net> writes:
    > In article <etor846a9fv.fsf@wormtongue.emschwar>, Eric Schwartz
    > <emschwar@ldl.fc.hp.com> wrote:
    >
    >> $weeknum = int((localtime)[7] / 7);
    >
    > Isn't that inaccurate?
    > int( 365 / 7 ) = 52
    Yeah, sorry:

    use POSIX;
    $weeknum = ceil((localtime)[7] / 7);
    > The 365th day of the year ( and on leap years, the 366th also) are in
    > the 53rd week..
    >
    > The OP might want to check CPAN for any number of Date manipulation
    > modules. 'The Perl Cookbook'[1] suggests Date::Calc.
    No disrespect intended to either the author of Date::Calc or the
    Cookbook, but using Date::Calc for this is rather like swatting a fly
    with an M1A1 Abrams. I use modules just about everywhere I can, but
    this is such a trivial problem that doesn't particularly need it.
    Now, if I wanted to find out what week the next day fell into, I'd
    surely use it.

    -=Eric
    --
    Come to think of it, there are already a million monkeys on a million
    typewriters, and Usenet is NOTHING like Shakespeare.
    -- Blair Houghton.
    Eric Schwartz Guest

  9. #8

    Default Re: how to know the week of today?

    Hi, all
    Thanks all of your help.

    "C&J" <ggkuo@yahoo.com> wrote in message
    news:OWlVa.662$Qb7.504188001@newssvr12.news.prodig y.com...
    > Hi,
    > Is there any way to know what is the current week?
    > January 1 is the first week.
    > Thanks
    > Chris
    >
    >

    C&J Guest

  10. #9

    Default Re: how to know the week of today?

    cp (cpryce@pryce.nospam.net) wrote on MMMDCXXI September MCMXCIII in
    <URL:news:310720031317510686%cpryce@pryce.nospam.n et>:
    {} In article <etor846a9fv.fsf@wormtongue.emschwar>, Eric Schwartz
    {} <emschwar@ldl.fc.hp.com> wrote:
    {}
    {} > $weeknum = int((localtime)[7] / 7);
    {}
    {} Isn't that inaccurate?
    {} int( 365 / 7 ) = 52
    {}
    {} The 365th day of the year ( and on leap years, the 366th also) are in
    {} the 53rd week..
    {}
    {} The OP might want to check CPAN for any number of Date manipulation
    {} modules. 'The Perl Cookbook'[1] suggests Date::Calc.
    {}
    {} [bash:~]user% perl -e 'use Date::Calc qw(Week_Number);\
    {} print Week_Number('2003', 12, 31), "\n";'
    {}
    {} outputs: 53


    The methods aren't equivalent, even when you change 'int' to 'ceil'.

    Take for instance Jan 6, 2003.

    ceil (6 / 7) == 1.

    but

    Week_Number (2003, 1, 6) == 2.


    The latter corresponds with the ISO standard on weeks: weeks start on
    Mondays, and week 1 is the week with the first Thursday of the year in
    it. This could mean some days of January are in week 52 or 53, and
    some days of December could be in week 1.

    The former method isn't any standard I know off - it would mean that
    weeks start on different days in different years.

    Americans, as usual, don't follow international standards. Week 1 in
    the US is the week January 1 falls in. Which may, or may not be the
    same as the POSIX standard, depending on the year.


    Abigail
    --
    perl -e '* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
    / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / /
    % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % %;
    BEGIN {% % = ($ _ = " " => print "Just Another Perl Hacker\n")}'
    Abigail Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139