Jump to content

How to add days to date and compare with weeknumbers?


Muiter

Recommended Posts

I am trying to get an query to see the total amount of invoices to paid per week when paying invoice at 60 days after receiving.


The query I have is running without problem but the results can not be correct. What might be causing the unexpected result?


In the query below I am trying to get the total amount of invoices to be paid in week 52/2015 with the invoice date of 60 days before week 52.



When using 30 and 60 days I have the result as below, but the total should be around 364k. (Don't mind the forst row, it's an different query)


LedDH.png



SELECT
SUM(amount) AS amount
FROM invoices
WHERE date_paid = '0000-00-00' AND WEEK(DATE_ADD(date_recieved, INTERVAL 60 DAY)) = 52 AND YEAR(DATE_ADD(date_recieved, INTERVAL 60 DAY)) = 2015

Link to comment
Share on other sites

It looks like you're asking it to show you the sum of invoices that were received 60 days before the last week of the year. Is that correct?

Not for the last week but for any week. Week 52 is just an example, it could be any week of the year.

Link to comment
Share on other sites

You should check what values you're actually summing up

SELECT
date_received, amount
FROM invoices
WHERE date_paid = '0000-00-00' AND WEEK(DATE_ADD(date_recieved, INTERVAL 60 DAY)) = 52 AND YEAR(DATE_ADD(date_recieved, INTERVAL 60 DAY)) = 2015

From what I can see your query is correct, but I don't know your actual specifications.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...