title: MySQL Custom Function To Select Record
body: <p>I am trying to create a custom function in MySQL that will take a UNIX date timestamp and convert it back to an actual date and in that function SELECT a value from a table based on that date.
  </p>
  
  <pre><code>Create function fiscal(current TIMESTAMP)
  Returns INT
  Begin
      Declare select_date DATE;
      Declare select_year INT(11);
      SET select_date = FROM_UNIXTIME(current);
      SET select_date = DATE_FORMAT(select_date, '%m-%d-%y');
      SET select_year = (SELECT Year FROM DateInfo WHERE DateInfo_ID = select_date);
      Return select_year;
  END
  </code></pre>
  
  <p>It returns a NULL value.</p>