Jennifer G. wrote: > How do I know this day is in NO. which week in this year? > for example, Jan 1 is in the no.1 week of this year. > but how about the current day?
It's a little more complicated than that. Week one is the first week in the year that has four or more days, so if Jan 1 falls on a Thursday or later it is in week 53 of the preceding year. The program below may help. Note that it assumes the first day of the week 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 weekday # my $jan1 = mktime(0, 0, 0, 1, 0, $year); my ($wday) = (localtime($jan1))[6]; # Calculate the number of days since the beginning of the week containing Jan 1 # If Jan 1 falls later than Wednesday then week one is a week later so subtract 7 days # The week number is the number of whole weeks since the Sunday of week 1 # $yday += $wday; $yday -= 7 if $wday > 3; my $wkno = int($yday / 7) + 1; -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/