title: Mysql relative date subtraction
body: <p>I have the following two tables</p>
  
  <pre><code># Event table
  id    title         start_date              end_date
  ----------------------------------------------------------
  1      Foo     2013-05-06 20:30:00     2013-05-06 22:45:00
  2      Bar     2013-06-03 07:40:00     2013-05-06 10:45:00
  3      Demo    2013-05-02 00:22:00     2013-05-06 03:45:00
  4      Test    2013-07-09 10:56:00     2013-05-06 13:45:00
  
  # Notification table
  id   event_id         mail         time    type     sent
  ----------------------------------------------------------
  1       1       123@example.com     15    minute     0
  2       1       234@example.com     01    day        0
  3       3       655@example.com     01    week       0
  4       4       888@example.com     40    minute     0
  5       4       999@example.com     42    minute     1
  5       4       987@example.com     30    minute     0
  </code></pre>
  
  <p>Every minute a cron job executes a PHP script to check if a notification should be sent to the email address in the notification table. The time value is the relative time before the start date of the event when the reminder should be sent.</p>
  
  <p>For example when the cron job runs at <em>2013-05-06 20:15:00</em> an email should be sent to the email address <strong>123@example.com</strong>. A sent flag should also be considered. If this is set to 0 then all notifications should be sent also if it is lower than the send date. For example when the cron job runs at <em>2013-07-09 10:26:00</em> a mail should be sent to <strong>987@example.com</strong> and <strong>888@example.com</strong>.</p>
  
  <p>My question is, how does the query have to look like in mysql to fetch the notifications to meet the requirements from above for the actual (now()) date? I tried with <a href="http://dev.mysql.com/doc/refman/5.1/en/date-and-time-functions.html#function_date-sub" rel="nofollow">date_sub</a> but was not really successful. An help is really appreciated.</p>