On Jan 29, Darryl Schnell said:
>I am currently working on a prorate billing routine for an online form
>and need a bit of guidance. The idea behind the program is to take 19.95
>and divde that by the total of remain days in the month, using the day
>of the month the user filled out the form as the starting point.
All you want to do can be handled with the standard Time::Local module:
use Time::Local;
my ($day, $mon, $yr) = (localtime)[3..5];
my ($n_mon, $n_yr) = ($mon + 1, $yr);
# wrap around
$n_yr++, $n_mon = 0 if $n_mon == 12;
# get the UNIX time of 12:00 noon of the first day of the next month
my $wanted_date = timelocal(0,0,12, 1,$n_mon,$n_yr);
# subtract a day's worth of seconds
$wanted_date -= 86400;
my $last_day = (localtime $wanted_date)[3];
Another approach is to merely build an array:
my ($mon,$yr) = (localtime)[4,5];
my @days = (31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);
my $last_day = $days[$mon];
# adjust for leap year
$last_day++ if
$mon == 1 and (
$yr % 400 == 0 or
($yr % 4 == 0 and $yr % 100 != 0)
);
And you'd be done. Either way is fine, really. It's up to you.
--
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 **
<stu> what does y/// stand for? <tenderpuss> why, yansliterate of course.
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]