February 1, 2019 at 1:03 am
Hi,
I have this situation, we are now on month FEB, I want data from Jan this year, even in DECEMBER I would still need to pull data from JAN this year, January next year I would still need data from 1 JAN 2019, BUT from FEB 2020, I want data from JAN 2020. So I basically want data from JAN on the current year provided we are on second month or more, if we are on the first month of the year, I want from Jan the previous year.
February 1, 2019 at 1:28 am
mediacommentry - Friday, February 1, 2019 1:03 AMHi,I have this situation, we are now on month FEB, I want data from Jan this year, even in DECEMBER I would still need to pull data from JAN this year, January next year I would still need data from 1 JAN 2019, BUT from FEB 2020, I want data from JAN 2020. So I basically want data from JAN on the current year provided we are on second month or more, if we are on the first month of the year, I want from Jan the previous year.
You could try something like this ...WHERE [YourDateField] >= DATEADD(YEAR, DATEDIFF(YEAR, 0, GETDATE()) -IIF(MONTH(GETDATE()) = 1,1,0), 0)
February 1, 2019 at 1:41 am
DesNorton - Friday, February 1, 2019 1:28 AMmediacommentry - Friday, February 1, 2019 1:03 AMHi,I have this situation, we are now on month FEB, I want data from Jan this year, even in DECEMBER I would still need to pull data from JAN this year, January next year I would still need data from 1 JAN 2019, BUT from FEB 2020, I want data from JAN 2020. So I basically want data from JAN on the current year provided we are on second month or more, if we are on the first month of the year, I want from Jan the previous year.
You could try something like this ...
WHERE [YourDateField] >= DATEADD(YEAR, DATEDIFF(YEAR, 0, GETDATE()) -IIF(MONTH(GETDATE()) = 1,1,0), 0)
Thank you.
February 1, 2019 at 7:39 am
This is another way of doing it.
WHERE [YourDateField] >= DATEADD( YY, DATEDIFF( YY, 0, DATEADD( mm, -1, GETDATE())), 0)
Viewing 4 posts - 1 through 3 (of 3 total)
You must be logged in to reply to this topic. Login to reply