if you are on the list since a couple of weeks, there was a really good
topic from japhy on this (he was helping me out)

There ya go:

<quoting>
I suggest you use the % operator (modulus) to save yourself a bit of
work.
Also, the rules for determining leap year are thus:

  divisible by 4
  BUT NOT divisible by 100
  UNLESS divisible by 400

Also, your validation function was broken for the month, since your
variable held one less than the actual month.

  sub valid_date {  # that's like a pun ;)
    my ($yr, $mon, $day) = @_;

    # general month and day sanity
    return if $mon < 1 or $mon > 12;
    return if $day < 1 or $day > 31;

    # April, June, September, November
    return if $day > 30 and
      ($mon == 4 or $mon == 6 or $mon == 9 or $mon == 11);

    # February, leap or not
    return if $mon == 2 and $day > (
      (($yr % 4 == 0 and $yr % 100 != 0) or ($yr % 400 == 0)) ? 29 : 28
    );

    # otherwise, it's an ok date
    return 1;
  }
</quoting>

This sub was checking a valid date, but with minor understanding of the
script you'll see it's easy to get the lastest day:-)

Etienne

Glenn Cannon wrote:
> 
> Thx japhy,
> 
> Does exactly what I need it to.
> 
> Now all I need is a way to work out the last day of the month.  Most of them
> should be easy, but that damn February...
> 
> Glenn Cannon
> [EMAIL PROTECTED]
> Level II Certified DCI Judge
> 'There is no spoon.'
> www.eventsbeyondbelief.com
> 
> > -----Original Message-----
> > From: Jeff 'japhy' Pinyan [mailto:[EMAIL PROTECTED]]
> > Sent: Thursday, November 15, 2001 1:49 PM
> > To: Glenn Cannon
> > Cc: [EMAIL PROTECTED]
> > Subject: Re: Day of the month
> >
> >
> > On Nov 15, Glenn Cannon said:
> >
> > >Given the month and the year, how can I derive what day the
> > first landed on?
> >
> > Using the standard Time::Local module, and the built-in
> > localtime() function.
> >
> >   use Time::Local;
> >   use strict;
> >
> >   my ($mon, $year) = (11, 2001);
> >   my $first = timelocal(0,0,0, 1, $mon-1, $year-1900);
> >
> >   my $dow = (localtime $first)[6];
> >   my $day = (qw( Sun Mon Tues Wednes Thurs Fri Satur ))[$dow] . "day";
> >
> > --
> > Jeff "japhy" Pinyan      [EMAIL PROTECTED]      http://www.pobox.com/~japhy/
> > RPI Acacia brother #734   http://www.perlmonks.org/   http://www.cpan.org/
> > ** Look for "Regular Expressions in Perl" published by Manning, in 2002 **
> >
> >
> > --
> > To unsubscribe, e-mail: [EMAIL PROTECTED]
> > For additional commands, e-mail: [EMAIL PROTECTED]
> >
> 
> --
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]

-- 
Etienne Marcotte
Specifications Management - Quality Control
Imperial Tobacco Ltd. - Montreal (Qc) Canada
514.932.6161 x.4001

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to