I'm tying to retrieve data from the 2 months ago. I tried WHERE = LAST_N_MONTHS:2 but this returns data from last month too. So for now I want everything from 1st July - 31st July. This needs to update each month too.

On the same subject how do I get the same but for last month last year e.g. 1st Aug 16 - 31st Aug 16?


This should work for records from two months ago (i.e. - Today is 25th September, that means 1st July - 31st July):

WHERE CreatedDate = LAST_N_MONTHS:2 AND CreatedDate < LAST_N_MONTHS:1

And the second query for records from 13 months ago, which is the previous month of last year (i.e. - Today is 25th Sep. 2016, so this will return 1st August - 31st August 2015):

WHERE CreatedDate = LAST_N_MONTHS:13 AND CreatedDate < LAST_N_MONTHS:12
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.