in reply to Determining the dayname for the last day of any given month
It works by substracting 1 second from the timestamp of 00:00:00 the first of the following month.#!/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"; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Determining the dayname for the last day of any given month
by Skeeve (Parson) on Jun 19, 2006 at 12:45 UTC |