How to get the no of Days from the difference of two dates in PostgreSQL? -
select extract(day age('2013-04-06','2013-04-04'));`
gives me no of days ! i.e.: 2
days
but failed when have differnt month:
select extract(day age('2013-05-02','2013-04-01'));
so need no of days 32
days
subtraction seems more intuitive.
select '2013-05-02'::date - '2013-04-01'::date
run query see why result 31 instead of 32
with dates ( select generate_series('2013-04-01'::date, '2013-05-02'::date, '1 day')::date end_date, '2013-04-01'::date start_date ) select end_date, start_date, end_date - start_date difference dates order end_date
the difference between today , today 0 days. whether matters application-dependent. can add 1 if need to.
Comments
Post a Comment