1

I have table called TrainingMatrix and it has a column called ExpiryDate. I am trying to write an SQL statement which can show me all records of 2012 as following:

 SELECT * FROM "TrainingMatrix" WHERE "ExpiryDate" - current_date < 0 AND EXTRACT(YEAR FROM TIMESTAMP "ExpiryDate") = 2012;

But this doesn't work, can any one help?

I am using PostgreSQL.

0

2 Answers 2

3

No timestamp word when using column:

... AND EXTRACT(YEAR FROM "ExpiryDate") = 2012 ...
Sign up to request clarification or add additional context in comments.

Comments

2

If you have index on ExpiryDate column - it's better to avoid using functions and have exact date/timestamp range:

and "ExpiryDate">='2012-01-01' and "ExpiryDate"<'2013-01-01';

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.