15 Minute Groupings of data
-
2010년 5월 21일 금요일 오후 2:16
I am trying to select data points in 15 minute intervals. I get the data I need but am unable to display a usable label (I am graphing the data on an ASP.net page). What I want to do is each hour group the data each quarter hour 00, 15, 30 and 45 and display it as 7:00, 7:15, 7:30 and 7:45. My select uses a UNION of 4 select statements (one for each quarter hour). My original thought was to concatenate the appropriate increment to the hour (datepart(hour,datefield)+ ':15') but I can not get the formatting correct to make it work. Any ideas or suggestions??
Thanks
모든 응답
-
2010년 6월 29일 화요일 오전 9:02
Is it a Data Mining topic?
Could you try a similar formula in your query, please?
SELECT OriginalDateTime,
DATEADD(MILLISECOND, - DATEPART(MILLISECOND, OriginalDateTime),
DATEADD(MINUTE, -(DATEPART(MINUTE, OriginalDateTime) % 15),
DATEADD(SECOND, - DATEPART(SECOND, OriginalDateTime), OriginalDateTime)
)
) AS TimeRoundedToQuarterHour FROM YourTable
Kind regards,
Zoli
-- Zoltán Horváth
-- MCITP SQL Server Business Intelligence Developer 2005, 2008
-- Please mark posts as answered or helpful where appropriate.- 답변으로 제안됨 Zoltán Horváth 2010년 12월 6일 월요일 오후 10:48
- 편집됨 Zoltán Horváth 2012년 3월 20일 화요일 오후 5:10 adding code block
-
2012년 3월 20일 화요일 오후 5:12
Or something like this:
SELECT OriginalDateTime,
DATEADD(MINUTE, -(DATEPART(MINUTE, OriginalDateTime) % 15),
CAST(CONVERT(varchar(16), OriginalDateTime, 121) AS datetime)) AS TimeRoundedToQuarterHour FROM YourTable
Hope this helps as well.
Regards,
Zoli- 답변으로 제안됨 koles 2012년 4월 10일 화요일 오전 9:47

