GETDATE()
is a function from TSQL. What you want to use instead is CURRENT_DATE
. Also, I improved your query a bit by using COALESCE
.
select projectid,
COALESCE(enddate,CURRENT_DATE) - startdate
as "duration" from projects;
You may want to refine the result using FLOOR()
as well to get exact days.