Hi Everyone,
I need an expression to query the previous three months in a sql table in an input tool. I don't need rolling 3 months. So for example, if I run the workflow on 5/20/19 I get the data for 2/1/19 to 4/30/2019 with the correct expression that I am looking for. I need to be able to run on any day of the current month of May and still be able to get data for 2/1/19 to 4/30/2019.
Thanks,
mackedet
Solved! Go to Solution.
Hi @Soxfaninfl
If it's a query in SQL Server, I'd use this where clause:
WHERE DATEADD(mm, -3, DATEADD(mm, DATEDIFF(mm, 0, GETDATE()), 0) <= YOURDATEFIELD AND DATEADD(DAY, -(DAY(GETDATE())), GETDATE()) >= YOURDATEFIELD
Cheers,
Hi @Soxfaninfl ,
For your calculations:
From
todate(tostring(tostring(DateTimeYear([DateTimeNow])) + "-0" + tostring(DateTimeMonth([DateTimeNow])-3)) + "-" + tostring(DateTimeDay([DateTimeNow])))
To
DateTimeParse(DateTimeAdd([DateTimeNow],-DateTimeDay(DateTimeNow()),"days"),"%Y-%m-%d")
Hi Thableaus,
Thank you for responding. I'm getting the following error. The field is a date/time field. Please advise.
I think there was a missing parenthesis:
WHERE
DATEADD(mm, -3, DATEADD(mm, DATEDIFF(mm, 0, GETDATE()), 0))
<= YOURDATEFIELD
AND DATEADD(DAY, -(DAY(GETDATE())), GETDATE())
>= YOURDATEFIELD
Thank you, Thableaus! This worked perfectly.
User | Count |
---|---|
17 | |
15 | |
15 | |
8 | |
5 |