Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Database & SysAdmin
  3. Database
  4. Round up/down minutes to next quater

Round up/down minutes to next quater

Scheduled Pinned Locked Moved Database
tutorialquestion
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • V Offline
    V Offline
    VK Cadec
    wrote on last edited by
    #1

    Hi, I need to round the minutes to the nearest quarter of hour. For example if it is 00:07 (hour:minutes) then it would be 00:15, if 00:05 then it would be 00:00. Any ideas how to go about doing this? Many thanks for your time.

    E 1 Reply Last reply
    0
    • V VK Cadec

      Hi, I need to round the minutes to the nearest quarter of hour. For example if it is 00:07 (hour:minutes) then it would be 00:15, if 00:05 then it would be 00:00. Any ideas how to go about doing this? Many thanks for your time.

      E Offline
      E Offline
      Eric Dahlvang
      wrote on last edited by
      #2

      Make a function:

      CREATE FUNCTION [dbo].[RoundMinutes]
      (@dDateTime datetime)
      RETURNS DateTime AS
      BEGIN
      declare @minutes int
      set @minutes = datepart(n,@dDateTime)

      set @minutes = case when @minutes < 7 then -@minutes
      when @minutes < 23 then -@minutes+15
      when @minutes < 37 then -@minutes+30
      when @minutes < 52 then -@minutes+45
      else 60-@minutes
      end
      return(dateadd(n,@minutes,@dDateTime))
      END

      Call it like this:

      select dbo.roundminutes(datefield) as RoundedDateField from mytesttable

      --EricDV Sig--------- Some problems are so complex that you have to be highly intelligent and well informed just to be undecided about them. - Laurence J. Peters

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups