July 19th, 2012, 08:24 AM
Select all from table in current month
How would I select * from a table where the data is always in the current month?
I have some code that kind of works in MS SQL
But it a) doesn't run in postgres and b) returns the last 6 months
select * from ainvdet WHERE [invoice_date] BETWEEN DATEADD(month,DATEDIFF(month,0,[invoice_date])-12,0) AND DATEADD(month,DATEDIFF(month,0,[invoice_date])-7,0)
Any help would be great
July 19th, 2012, 08:55 AM
where date_trunc('month', invoice_date) = date_trunc('month', current_date);
where extract(year from invoice_date) = extract(year from current_date)
and extract(month from invoice_date) = extract(month from current_date);
I will not read nor answer questions where the SQL code is messy and not formatted properly using [code] tags.
Tips on how to ask better questions: