Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8947959
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T12:53:31+00:00 2026-06-15T12:53:31+00:00

I have a function to round a datetime to the nearest quarter hour. But

  • 0

I have a function to round a datetime to the nearest quarter hour.
But is there a method to round down to the nearest quarter instead?

Example.

08:14:00 becomes 08:00:00
08:03:00 becomes 08:00:00
08:29:00 becomes 08:15:00 
08:55:00 becomes 08:45:00

This is what I have now to round to the nearest quarter.

(
@dt datetime
)
returns datetime
as
begin
declare @result datetime
declare @mm int
set @mm=datepart(minute,@dt)
set @result = dateadd(minute,-@mm + (round(@mm/cast(15 as float),0)*15) , @dt )

return @result
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T12:53:32+00:00Added an answer on June 15, 2026 at 12:53 pm

    Using SQL Server:

    select cast( 
             FLOOR( cast( GetDate() as float)*(24*4)) / (24*4) 
           as smalldatetime) AS "datetime_quarter"
    

    The strategy is:

    • Convert the date to a float number, *24 to get number of hours, *4 to get number of quarters
    • Round down with FLOOR
    • Convert back to number of days by /(24*4)
    • Convert number of days to a datetime. smalldatetime is used to avoid float rounding issues.

    This can easily be adjusted to use ROUNDor CEILING instead; or to use other hour multiples instead of 4 (quarters).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following function definition (docstring simplified for this example): def ui(*classes, call_init=False):
I Have folowing Sql query in which i am using round function but it
Refer to this article: math-round-vs-hack We have Math functions optimized. We use (num+0.5)|0 instead
I have function like this: function ypg_delete_img($id, $img) { $q = $this->ypg_get_one($id); $imgs =
I have function LoadTempMovieList(), and need to load movies from sessionStorage. But it seems
I have function like this: function gi_insert() { if(!IS_AJAX){ $this->load->library('form_validation'); $this->form_validation->set_rules('name', 'Naslov', 'trim|required|strip_tags'); $this->form_validation->set_rules('body',
I currently have a function which will take an input and round it to
I have a issue in SSRS when I use expression to use Round function
I have a simple round function. It rounds to an even number. I want
I have 2 decimal numbers: 1999,9999 1999,99 if I use function decimal.Round(Temp, 2); then

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.