Skip to content
Advertisement

How to Fetch Data By using Two Date Columns in PostgreSQL SQL?

I m Trying to Fetch Data by using Two Date column in PostgreSQL. It is giving me the correct the output according to the query. But it is not giving me my expected result. enter image description here

In this Output i fetched data by using document_submission_date and received_date of February month but it is giving me some output of the month of march which I indicated with the blue sign. yap, for sure it is giving me the correct result according to the query. but i only want to return all data except the blue indicator (image above). this is my query given below..

I have been trying to solve this problem since yesterday but i could’t find any solution of this. It will be very helpful to me to if any one help me to solve this problem. If anyone help to solve this by Linq Query, that will be helpful too.

Advertisement

Answer

This seems to work as expected. Consider these conditions in your WHERE clause:

This predicates filters on rows where either received_date or document_submission_date belong to the month of February. What you are showing in your current results satisfies these conditions.

If you want both columns in February, use AND instead of OR. I would also recommend using date literals and half-open intervals as these make the query shorter and easier to read:

Side note: you should really fix your schema and store date values as date datatypes. Storing dates as strings is a bad practice that makes things inefficient and unnecessarily complicated.


If you want to all nulls in document_submission_date, then:

User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement