how to use a date module within a cron to send out 2 day, 7day, 30day messages?

Posted on 2004-04-08
Medium Priority
Last Modified: 2010-03-04

I'm writing a script that sends out remindermessages 2days, 7days, and 30days after a customer signs up with my services.

I currently log all orders in a log file...  I'm able to retrieve the date/email from the log file....  and I'm able to send people email messgaes just fine in my script.  The problem is that I have no idea how to use a date function to determine which customers need to be sent a message.  I assume it is probably like 5 lines of code if any one here is familiar with a date module.

So for example:  

Today is April 1st.  Therefore I run the cron at 1am on April 1st.    I have a client that signed up on March 30th.  (2 days ago).  How do I go about determining, that this customer needs to be sent an email?  The variable I use for the day the client signed up is $signupdate .   $signupdate is in this format:  4-1-2004

Any help would be much appreciated.  


Question by:wyatt12
  • 3
LVL 28

Expert Comment

ID: 10788483
use Date::Manip;


When I have a few extra minutes, I'll post some example code that you can use.
LVL 10

Expert Comment

ID: 10789627
use Date::Calc qw(Add_Delta_Days);

if($signupdate=~m/(\d+)-(\d+)-(\d{4})/) {
      ($y2, $m2, $d2) = Add_Delta_Days($ysignup, $msignup, $dsignup, 2);
      ($y7, $m7, $d7) = Add_Delta_Days($ysignup, $msignup, $dsignup, 7);
      ($y30, $m30, $d30) = Add_Delta_Days($ysignup, $msignup, $dsignup, 30);
      ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) =localtime(time);      
        #print "$today,$date2,$date7,$date30\n";
        if($today eq $date2 || $today eq $date7 || $today eq $date30) {
              print "We should send reminder today\n";
        } else {
              print "We should not send reminder today\n";

Accepted Solution

davorg earned 1000 total points
ID: 10789782
You can do it all without having to resort to installing new modules from CPAN.

use Time::Local;

use constant DAY => 24  * 60 * 60;
use constant TWO_DAYS = 2 * DAY;
use constant SEVEN_DAYS => 7 * DAY;
use constant THIRTY_DAYS => 30 * DAY;

my $signupdate = '4-1-2004'; # 4th Jan 2004 in any sensible country :)

my ($d, $m, $y) = split /-/, $signupdate;

my $signup_secs = timelocal(0, 0, 0, $d, $m - 1, $y - 1900);
my $now = time;

my $diff = $now - $signup_secs;
if ($diff > TWO_DAYS and $diff < (TWO_DAYS + DAY)) {
  # send two day reminder

if ($diff > SEVEN_DAYS and $diff < (SEVEN_DAYS + DAY)) {
  # send seven day reminder

if ($diff > THIRTY_DAYS and $diff < (THIRTY_DAYS + DAY)) {
  # send thirty day reminder

LVL 10

Assisted Solution

rj2 earned 1000 total points
ID: 10789809
Or somewhat shorter like this

use Date::Calc qw(Delta_Days);

if($signupdate=~m/(\d+)-(\d+)-(\d{4})/) {
      ($mday, $mon, $year) = (localtime)[3,4,5];
        #print "$diff\n";
        if($diff==2 || $diff==7 || $diff==30) {
              print "We should send reminder today\n";
        } else {
              print "We should not send reminder today\n";
LVL 10

Expert Comment

ID: 10789826
Run command below to install module Date::Calc if not already installed

perl -MCPAN -e 'install Date::Calc'

Date::Calc is a nice module because it can do all the most common date calculations and is also much faster that Date::Manip.

Featured Post

Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I've just discovered very important differences between Windows an Unix formats in Perl,at least 5.xx.. MOST IMPORTANT: Use Unix file format while saving Your script. otherwise it will have ^M s or smth likely weird in the EOL, Then DO NOT use m…
Checking the Alert Log in AWS RDS Oracle can be a pain through their user interface.  I made a script to download the Alert Log, look for errors, and email me the trace files.  In this article I'll describe what I did and share my script.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
Six Sigma Control Plans
Suggested Courses

612 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question