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

Posted on 2004-04-08
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
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 250 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 250 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

On Microsoft Windows, if  when you click or type the name of a .pl file, you get an error "is not recognized as an internal or external command, operable program or batch file", then this means you do not have the .pl file extension associated with …
There are many situations when we need to display the data in sorted order. For example: Student details by name or by rank or by total marks etc. If you are working on data driven based projects then you will use sorting techniques very frequently.…
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

636 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