title: How to convert FROM sas date format TO int in postgres (Amazon redshift)?
body: <p>Bear with me, because I don't have the vocab down. I am converting SAS dates to int using Navicat with postgresql. I have successfully used </p>
  
  <pre><code>DATEADD(day,round(field_name)::int,'19600101') -&gt; where field_name = '-8705' stored 
  as varchar(256)
  </code></pre>
  
  <p>for positive numbers, but this doesn't work for the negative numbers (pre Jan 1, 1960). Ideally, someone has a better/easier/more efficient way to convert from SAS dates, but I will be grateful for a way to convert these negative numbers to int. I have searched the Amazon Redshift documentation, and if the answer is in there I did not understand it. I learn best from examples, if possible. </p>
  
  <p>This example seemed promising, but I couldn't figure out how to get it to work for my situation:</p>
  
  <pre><code>SELECT total_days
   , CAST(end_date AS timestamp) t_stamp
   , CAST(end_date AS date) final_date_time
   -- date(end_date) will not work as end_date is date already
   , TO_CHAR(TRUNC(end_date), 'MM/DD/YYYY') final_date
  FROM(
  SELECT ROUND(1344444527/60/60/24)         total_days
      , TO_DATE('01-01-1960','dd-mm-yyyy') start_date
      , TO_DATE('01-01-1960','dd-mm-yyyy')+ (1344444527/60/60/24) end_date
   FROM dual
  )
  </code></pre>
  
  <p>Thanks, in advance, for your help!!</p>