convert date to integer in postgresql

date, integer, postgresql, sql

Solution

Simply subtract the two dates:

select date '2011-11-01' - date '1900-01-01'

the result will be the number of days.

More details in the manual: http://www.postgresql.org/docs/current/static/functions-datetime.html

Problem

I'm trying to convert a date (date type) into int. This int should be something like the number of days since the 1 January 1900. How to get this in postgresql? In excel I'm getting this automatically when i concatenate a date with a string. Example : 2011/11/01 convert into int as 36831

Original source