
Hey Guys! I want to generate last month report every time. so i have wrote Advance SQL custom query so how do i define or how SQL calculate time for Last month report?
in existing template Orion has SQL inbuilt magic to calculate DateTime between but how it will work with Advance SQL syntax?
Assuming the field you want to filter on is DateTime:
DateTime BETWEEN DATEADD(MONTH,-1,DATEADD(mm, DATEDIFF(m,0,GETDATE()),0)) AND DATEADD(s,-1,DATEADD(mm, DATEDIFF(m,0,GETDATE()),0))
Perfect answer!!! This is what i was looking for. Great!
Do you know how do i just print it to display what time it calculating ? I mean i want to test this code?
What about last 6 month? Just replace -1 with -6 ? Like following?
DateTime BETWEEN DATEADD(MONTH,-6,DATEADD(mm, DATEDIFF(m,0,GETDATE()),0)) AND DATEADD(s,-6,DATEADD(mm, DATEDIFF(m,0,GETDATE()),0))
If you are pulling APM data keep in mind that APM entries are based off of UTC time, so if you need data down to the hour or less use GETUTCDATE instead of GETDATE when working with APM information.
You shouldn't need to change the second -1, just the first one.
Thanks for info but why? its using UTC time? any special reason for this?