Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot

Re: Finding the dates for the reminder mail system

by eighty-one (Curate)
on Nov 08, 2008 at 20:44 UTC ( #722432=note: print w/replies, xml ) Need Help??

in reply to Finding the dates for the reminder mail system

So, to sum up, you want to . . .
  1. Have your script find the day of the week today
  2. If it's a Wed or Fri, query your db and find all projects due today+14 days into the future or sooner. Else, end the script
  3. Foreach of those, see if there is another Wed or Fri between now and the due date. If so, send a reminder. If not, send a reminder and a notice to management.

If you haven't already, look at The Many Dates and Times of Perl.

I prefer to work with epoch time when doing calculations, and convert back to other formats for db queries or display.

I would get the epoch time, then find the day of the week with Date::Day. Adding 14*24*60*60 to the current epoch time give you the epoch time two weeks from now (since epoch is in seconds, convert 14 days to hours then minutes then seconds to find that, thus 14*24*60*60). I assume you're using a databse to store projects, so just query for all projects due BETWEEN those two dates, after having converted them into a format the db likes.

  • Comment on Re: Finding the dates for the reminder mail system

Replies are listed 'Best First'.
Re^2: Finding the dates for the reminder mail system
by TGI (Parson) on Nov 10, 2008 at 07:41 UTC

    Your link is broken. Try The Many Dates and Times of Perl. Your suggestion to read this article is spot on. It is definitely worth reading.

    You've got to be careful doing epoch calculations. What happens over daylight savings time shifts? You can have a 23 or 25 hour day. Depending on the time you run your script you can wind up with the wrong date. There are other opportunities for errors as well.

    In most cases, you are better off using a library like DateTime (my personal favorite) to handle these calculations. Other options are mentioned in the article you suggested.

    To get a date two weeks from now with DateTime simply write:

    my $due_date = DateTime->now->add( weeks => 2 );

    That seems easier to understand than adding 2*7*24*60*60. It also is less likely to generate an error.

    TGI says moo

Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://722432]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (6)
As of 2021-10-28 20:18 GMT
Find Nodes?
    Voting Booth?
    My first memorable Perl project was:

    Results (96 votes). Check out past polls.