Ask a Question related to PERL Miscellaneous, Design and Development.
-
Brian McCauley #1
Re: how to know the week of today?
"C&J" <ggkuo@yahoo.com> writes:
POSIX::strftime supports at least one of the widely used "week number"> Is there any way to know what is the current week?
algorithms, more on some platforms. (Note that the ISO and POSIX
standards do not agree).
That alone does not uniquely define your week number algorithm.> January 1 is the first week.
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
-
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... -
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... -
Since today is October 31...
srand 0 puts "pH p!aoHalnyweel".split("").sort {|x,y| rand <=> rand }.join Cheers, Hal(loween)9000 -
[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... -
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. -
DOV LEVENGLICK #2
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
-
Gunnar Hjalmarsson #3
Re: how to know the week of today?
DOV LEVENGLICK wrote:
Err.. How is that solution related to OP's question?> 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]];
--
Gunnar Hjalmarsson
Email: [url]http://www.gunnar.cc/cgi-bin/contact.pl[/url]
Gunnar Hjalmarsson Guest
-
Eric Schwartz #4
Re: how to know the week of today?
Gunnar Hjalmarsson <noreply@gunnar.cc> writes:
Not at all, AFAICT, but the solution is in localtime():> DOV LEVENGLICK wrote:>>> C&J wrote:>> $thisday = (Sun,Mon,Tue,Wed,Thu,Fri,Sat)[(localtime)[6]];>>>Is there any way to know what is the current week?
>>>January 1 is the first week.
> Err.. How is that solution related to OP's question?
$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
-
cp #5
Re: how to know the week of today?
In article <etor846a9fv.fsf@wormtongue.emschwar>, Eric Schwartz
<emschwar@ldl.fc.hp.com> wrote:
Isn't that inaccurate?> $weeknum = int((localtime)[7] / 7);
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
-
JR #6
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>...
## This may be helpful to you. Good luck. --JR> Hi,
> Is there any way to know what is the current week?
> January 1 is the first week.
> Thanks
> Chris
#!/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
-
Eric Schwartz #7
Re: how to know the week of today?
cp <cpryce@pryce.nospam.net> writes:
Yeah, sorry:> 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
use POSIX;
$weeknum = ceil((localtime)[7] / 7);
No disrespect intended to either the author of Date::Calc or the> 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.
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
-
C&J #8
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
-
Abigail #9
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



Reply With Quote

