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.



In reply to Re: Credit Card Billing by Jazz
in thread Credit Card Billing by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.