Beefy Boxes and Bandwidth Generously Provided by pair Networks DiBona
The stupid question is the question not asked
 
PerlMonks  

Re: Determining the dayname for the last day of any given month

by Skeeve (Vicar)
on Jun 19, 2006 at 11:52 UTC ( #556232=note: print w/ replies, xml ) Need Help??


in reply to Determining the dayname for the last day of any given month

My approach using standard module Time::Local:

#!/usr/bin/perl -w use strict; use Time::Local; while (1) { print "Enter year (yyyy) and month (mm), separated by a space:"; chomp(my $input = <STDIN>); last if !$input; my ($year, $month) = split / /, $input; my $dayname = (qw(Sun Mon Tue Wed Thu Fri Sat))[(gmtime(timegm(0,0 +,0,1,$month % 12,$year + $month / 12)-1))[6]]; print "The last day of $month/$year will be a $dayname\n"; }
It works by substracting 1 second from the timestamp of 00:00:00 the first of the following month.

s$$([},&%#}/&/]+}%&{})*;#$&&s&&$^X.($'^"%]=\&(|?*{%
+.+=%;.#_}\&"^"-+%*).}%:##%}={~=~:.")&e&&s""`$''`"e


Comment on Re: Determining the dayname for the last day of any given month
Select or Download Code
Re^2: Determining the dayname for the last day of any given month
by Skeeve (Vicar) on Jun 19, 2006 at 12:45 UTC
    After reaeding greenFox' comment I realised: Substracting isn't necessary!
    #!/usr/bin/perl -w use strict; use Time::Local; while (1) { print "Enter year (yyyy) and month (mm), separated by a space:"; chomp(my $input = <STDIN>); last if !$input; my ($year, $month) = split / /, $input; my $dayname = (qw(Sat Sun Mon Tue Wed Thu Fri))[(gmtime(timegm(0,0 +,0,1,$month % 12,$year + $month / 12)))[6]]; print "The last day of $month/$year will be a $dayname\n"; }
    Simply rotate the daynames...

    s$$([},&%#}/&/]+}%&{})*;#$&&s&&$^X.($'^"%]=\&(|?*{%
    +.+=%;.#_}\&"^"-+%*).}%:##%}={~=~:.")&e&&s""`$''`"e

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://556232]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (12)
As of 2014-04-17 07:45 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    April first is:







    Results (441 votes), past polls