0

I am trying to calculate the difference between dates in days. Datatype is Text for columns snapshot_date and date_opened.I am getting an ERROR: function date_part(unknown, integer) does not exist

SELECT DATE_PART('day', snapshot_date::date -date_opened::date)::number from my_table
user8545255
  • 761
  • 3
  • 9
  • 21

1 Answers1

0

As documented in the manual subtracting one date from the other returns an integer representing the number of days, so:

snapshot_date::date - date_opened::date

is all you need.

This assumes that both columns can safely be cast to a date.