15 Minute Groupings of data RRS feed

  • Question

  • 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??




    Friday, May 21, 2010 2:16 PM

All replies

  • Is it a Data Mining topic?

    Could you try a similar formula in your query, please?

    SELECT OriginalDateTime,


    DATEADD(MINUTE, -(DATEPART(MINUTE, OriginalDateTime) % 15),

    DATEADD(SECOND, - DATEPART(SECOND, OriginalDateTime), OriginalDateTime)


    ) AS TimeRoundedToQuarterHour FROM YourTable

    Kind regards,

    -- Zoltán Horváth
    -- MCITP SQL Server Business Intelligence Developer 2005, 2008
    -- Please mark posts as answered or helpful where appropriate.
    Tuesday, June 29, 2010 9:02 AM
  • 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.

    • Proposed as answer by koles Tuesday, April 10, 2012 9:47 AM
    Tuesday, March 20, 2012 5:12 PM
  • It did not work. Thank you for your help.

    Friday, March 27, 2020 6:09 PM
  • Why? What happened?
    Wednesday, April 8, 2020 5:54 PM