1

I'm trying to get it as:

SELECT * FROM "Employee" WHERE TIMESTAMPDIFF('YEAR', "BirthDate", "HireDate");

but I get the next error:

ERROR:  function timestampdiff(unknown, timestamp without time zone, timestamp without time zone) does not exist
LINE 1: SELECT * FROM "Employee" WHERE TIMESTAMPDIFF('YEAR', "BirthD...
                                   ^
HINT:  No function matches the given name and argument types. You might need to add explicit type casts.

I've found another way to get difference between 2 dates but in my instructions it says that I have to get it via TIMESTAMPDIFF. Can someone help me where to look and how to fix my error?

2
  • "HireDate" - "BirthDate" There is no timestampdiff in Postgres - whatever those instructions are, they are clearly for a different DBMS product. postgresql.org/docs/current/static/functions-datetime.html Commented Oct 21, 2018 at 17:34
  • @a_horse_with_no_name you mean to switch places? I've tried it also and I got the same error Commented Oct 21, 2018 at 17:35

1 Answer 1

3

you can use minus operator

EXTRACT(DAY FROM (HireDate)-(BirthDate)) AS DateDifference

Example select date '2001-10-01' - date '2001-09-28'

DEMO IN FIDDLE

PostGrey Docs

Sign up to request clarification or add additional context in comments.

3 Comments

Interesting. This works with -, but it doesn't work with age().
with age , date_part('year', age("BirthDate", "HireDate"))
so how I understood there is no TIMESTAMPDIFF in PostgreSQL, right? By the way, thanks for the answer!

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.