Code Comments
Programming Forum and web based access to our favorite programming groups.How do I know this day is in NO. which win this year? for example, Jan 1 is in the no.1 w
of this year. but how about the current day? Thanks.
Post Follow-up to this messageIf you are calculating it your self and assuming you are intrested in the ISO defenition of the wnumber: http://www.proesite.com/timex/wkcalc.htm Of course there are modules on CPAN that do the same but then again, if all you want to know is the number of the w
it might be simpler to calculate it rather then adding a module requirement to your perl code. (depends a bit on how portable your code needs to be) Regards, Rob On Wed, Apr 2, 2008 at 2:00 PM, Jennifer G. <practicalperl@gmail.com> wrote: > How do I know this day is in NO. which w
in this year? > for example, Jan 1 is in the no.1 w
of this year. > but how about the current day? > Thanks. > > -- > To unsubscribe, e-mail: beginners-unsubscribe@perl.org > For additional commands, e-mail: beginners-help@perl.org > http://learn.perl.org/ > > >
Post Follow-up to this messageJennifer G. wrote: > How do I know this day is in NO. which win this year? > for example, Jan 1 is in the no.1 w
of this year. > but how about the current day? It depends on how you define "w
". The simple answer is: $ perl -le'print int( ( localtime )[ 7 ] / 7 )' 13 Perhaps have a look at the Date::Calc and Date::Manip modules (or many of the other Date related modules on CPAN.) John -- Perl isn't a toolbox, but a small machine shop where you can special-order certain sorts of tools at low cost and in short order. -- Larry Wall
Post Follow-up to this messageJennifer G. wrote: > How do I know this day is in NO. which win this year? > for example, Jan 1 is in the no.1 w
of this year. > but how about the current day? It's a little more complicated than that. W
one is the first w
in the year that has four or more days, so if Jan 1 falls on a Thursday or later it is in w
53 of the preceding year. The program below may help. Note that it assumes the first day of the w
to be Sunday. Rob use strict; use warnings; use POSIX qw/mktime/; # Fetch the year and day of year for today # my ($year, $yday) = (localtime)[5, 7]; # Build a date on January 1 of the current year and get its w
day # my $jan1 = mktime(0, 0, 0, 1, 0, $year); my ($wday) = (localtime($jan1))[6]; # Calculate the number of days since the beginning of the w
containing Jan 1 # If Jan 1 falls later than Wednesday then w
one is a w
later so subtract 7 days # The w
number is the number of whole w
s since the Sunday of w
1 # $yday += $wday; $yday -= 7 if $wday > 3; my $wkno = int($yday / 7) + 1;
Post Follow-up to this message
Show a Printable Version
Email This Page to Someone!
Receive updates to this thread
Powered by vBulletin
Copyright 2000-2006 Jelsoft Enterprises Limited.