I trying to fetch data for the latest full half hour as per the clock time.
for example if getdate() return me '2016-11-14 10:14:25.567' , i want data from '2016-11-14 09:30:00.000' to '2016-11-14 10:00:00.000'
I trying to fetch data for the latest full half hour as per the clock time.
for example if getdate() return me '2016-11-14 10:14:25.567' , i want data from '2016-11-14 09:30:00.000' to '2016-11-14 10:00:00.000'
I think you want something like this;
DECLARE @DateVariable datetime; SET @DateVariable = GETDATE()
SELECT
@DateVariable Current_DateTime
,DATEADD(mi,-30, CONVERT(smalldatetime, ROUND(CAST(@DateVariable AS float) * 48.0,0,1)/48.0) ) From_Time
,CONVERT(smalldatetime, ROUND(CAST(@DateVariable AS float) * 48.0,0,1)/48.0) To_Time
Where the date variable is now (2016-11-14 16:26:52) it will give you the last full half hour
The result will look like this;
Current_DateTime From_Time To_Time
2016-11-14 16:26:52.073 2016-11-14 15:30:00 2016-11-14 16:00:00