Jump to content

Recommended Posts

Posted

Hello,

I have a report which returns results over the last 220 days using this variable:

DATE_SUB(CURDATE(), INTERVAL 220 DAY)

This works well but I would like to run the same report for the 220 days prior to that.

I thought I could use: DATE_SUB(CURDATE() - 220, INTERVAL 220 DAY) but it doesn't seem to work.

Is that the right way to do this or is it not achievable?

Many thanks

Posted

You could try with:

DATE_SUB(DATE_SUB(CURDATE(), INTERVAL 220 DAY), INTERVAL 220 DAY)

but I can't be sure that would work, I'm not sure how happy SQL is with nested functions.

Also, depending on the WHERE clause, that may just return the last 440 days.

Update:

BETWEEN DATE_SUB(DATE_SUB(CURDATE(), INTERVAL 220 DAY), INTERVAL 220 DAY)AND DATE_SUB(CURDATE(), INTERVAL 220 DAY)

would be from -440 days to -220 days, I believe, but do get someone more familiar with SQL to check first.

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...