Advertisement

04.21.2008 at 10:07PM PDT, ID: 23341874
[x]
Attachment Details

SQL / TSQL - DATETIME - To The Nearest Half Hour, Hour, 2nd Hour, MORE:

Asked by sdswiger in SQL Query Syntax, MS SQL Server

Hello:

I've searched quite a bit and found a few solutions but not anything solid that currently works.  What I'm trying to do is basically round the time part to the nearest 30 minute, hour, etc...as displayed below:

Rounding the same as numbers such as if rounding to the nearest 10th, 4.9 is 0, 5 is 10, 12.2 is 10, etc...Same concept with time.

ITEMS LOOKING FOR: (the date should not be considered at all, will be removed, no problem on this)
1) Round to the nearest Half Hour
2) Round to the nearest Hour
* 3) Round to the nearest 2nd Hour in a 24-Hour period
** 4) Round to the nearest 4th Hour in a 24-Hour period
*** 5) Round to the nearest 6th Hour in a 24-Hour period
**** 6) Round to the nearest 12th Hour in a 24-Hour period

* 2ND HOUR - 24-Hour period would be 12:00 AM, 2:00 AM, 4:00 AM, etc...all the way to 10:00 PM being the last 2-Hour period.

** 4TH HOUR - 24-Hour period would be 12:00 AM, 4:00 AM, 8:00 AM, etc...all the way to 8:00 PM being the last 4-Hour period.

*** 6TH HOUR - 24-Hour period would be 12:00 AM, 6:00 AM, 12:00 PM, and 6:00, all being the complete 6-Hour period.

**** 12TH HOUR - 24-Hour period would be 12:00 AM and 12:00 PM, both being the complete 12-Hour period.

Start Free Trial
[+][-]04.21.2008 at 10:27PM PDT, ID: 21408270

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]04.21.2008 at 10:36PM PDT, ID: 21408303

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]04.21.2008 at 10:41PM PDT, ID: 21408323

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]04.21.2008 at 10:54PM PDT, ID: 21408359

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zones: SQL Query Syntax, MS SQL Server
Sign Up Now!
Solution Provided By: ee_rlee
Participating Experts: 2
Solution Grade: A
 
 
[+][-]04.22.2008 at 01:24AM PDT, ID: 21408967

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
 
Loading Advertisement...
20080716-EE-VQP-32 / EE_QW_2_20070628