in reply to Credit Card Billing
I use Class::Date for date comparisons. It facilitate comparisons with past, present and future dates.
use Class::Date qw/ date localdate now /; # date that the billing period starts (get data from db) my $period_start = date('2001-12-31'); # date to start attempting charges (get data from db) my $charge_date = date('2001-12-27'); my $today = date( localdate( now ))->truncate; # truncate makes time m +idnight # it's late if ( $charge_date < $today ){ print "Charge date passed. Transaction previously failed. Try aga +in.\n"; } # not yet due elsif ( $charge_date > $today ) { print 'Charge to be processed in ', +( $charge_date - Class::Date->new( $today ) )->day, ' days.'; } # charge today else { print 'Today is charge date. If successful, next charge date will + be: ', date( $charge_date + '1M'); # one month # change next charge date in BillSchedule table. }
An alternative is to use Date::Calc, which was discussed recently here. Depending on how many comparisions you'll be doing, Date::Calc may be the best choice because it's much faster.
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Re: Credit Card Billing
by rob_au (Abbot) on Jan 06, 2002 at 08:32 UTC |
In Section
Seekers of Perl Wisdom