Jump to content

How to add days to date and compare with weeknumbers?


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 post
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 post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...