in reply to Compare Date
There is a major flaw with this application logic - What if the signup was performed on the 31st of a month? Using this approach to this problem, the emails would be sent out to the user seven times over the year, that is, only those months with 31 days. In short - it doesn't work.
When faced with this application requirement previously, I approached this problem somewhat differently. The approach taken was to have the script check the number of days since the sign up was performed and send out the email if thirty days have passed - Or more specifically, the number of days within the year, divided by the number of emails which you wish to send to the user over the year.
To implement this application logic, the Date::Calc module proved to offer all of the date-related functions required - A snippet of the code employed follows:
use Date::Calc qw/:all/; . . my @date = (Localtime)[0..2]; . . # iterate through system accounts from the database while (my $account = $accounts->fetchrow_hashref) { my $plan = $plans[ $account->{'planid'} ]; # calculate the delta day count between the current date and the + # date of account activation my $delta = Delta_Days((split '-', $account->{'activationdate'}), +@date); if ($delta == 0) { # the delta day count will equal zero on the same day as the + # account activation - this is useful for when you also want + to # incorporate the sending of a welcome email or alike } else { # within this system each billing plans has a period value w +hich # represents the number of billing systems over a single ann +ual # period - if you are wanting to send out these emails on a # monthly basis, this variable can be replaced with the numb +er # twelve if ($plan->{'fee'} && $plan->{'period'}) { # here is the actual calculation itself, the modulus res +ult # of which will equal zero on days when an email should +be # sent to the user my $calc = $delta % int (Days_in_Year((@date)[0..1]) / $pl +an->{'period'}); if ($calc == 0) { # send the email to the owner of this account } } } }
For this project, I did also look at other date-related modules on CPAN but found the scope and module documentation of Date::Calc by far the most complete and inviting to work with.
perl -e 's&&rob@cowsnet.com.au&&&split/[@.]/&&s&.com.&_&&&print'
|
|---|