title: MySQL date difference check within a trigger
body: <p>Within a trigger before I insert some data into a table, I would want it to check, whether the difference of dates of events I am entering is greater than or equal to 1 day. There can only be one event in one club taking place each day.</p>
  
  <p><strong>Sample story</strong></p>
  
  <p>If there already is <code>2014-01-01 19:00:00</code> date in database and I'm trying to insert another record with <code>2014-01-01</code> date (hour does not matter), it <strong>should not allow it</strong>.</p>
  
  <p><strong>Partial code from the trigger</strong></p>
  
  <pre><code>DECLARE k INT DEFAULT 0;
  
  /* This is where I get the error, ABS is to make it always positive to go through  
  checking, so that it wont matter whether the NEW date is before or after */
  
  SELECT ABS(DATEDIFF(DATE_FORMAT(`performance_date`, '\'%Y-%m-%d %H:%i:%s\''), 
  DATE_FORMAT(NEW.`performance_date`, '\'%Y-%m-%d %H:%i:%s\''))) INTO k;
  
  /* Below code is out of scope for this question */
  
  IF k = 0 THEN
      SIGNAL SQLSTATE '58005'
      SET MESSAGE_TEXT = 'Wrong! Only 1 performance in 1 club is allowed per day! Change your date, or club!';
  END IF;
  </code></pre>
  
  <blockquote>
    <p>Error Code: 1054. Unknown column 'performance_date' in 'field list'</p>
  </blockquote>
  
  <p>I've tried something as simple as:</p>
  
  <pre><code>...DATEDIFF(`performance_date`, NEW.`performance_date`)
  </code></pre>