Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Get hour only from DateTime ms sql convert to int

Posted on 2011-03-11
5
Medium Priority
?
1,224 Views
Last Modified: 2012-05-11
I need to get the current hour in 24 hour format and convert it to an int in a ms sql 2005 stored procedure... can ayone help me with this please
0
Comment
Question by:QuinnDester
  • 3
  • 2
5 Comments
 
LVL 143

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 2000 total points
ID: 35108529
DATEPART(hour, yourfield)
0
 
LVL 3

Author Closing Comment

by:QuinnDester
ID: 35109201
Thank you, works like a charm,
0
 
LVL 3

Author Comment

by:QuinnDester
ID: 35109295
just an expantion on this, i want my query to check to see if the row was lastupdated within the hour in question.

but it will need to take the day into account too, as the last update may have been same time yesterday.

can i use datediff to check within this hour, or will that check within an hour, even if that falls in the previous hour
0
 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 35109406
that would be like this for the last hour:
where yourfield >= dateadd(hour, -1, getdate())
  and yourfield <= getdate()

Open in new window


otherwise, you can also check on the date part as such first ...
0
 
LVL 3

Author Comment

by:QuinnDester
ID: 35110992
thank you....  your a life saver :)
0

Featured Post

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In the first part of this tutorial we will cover the prerequisites for installing SQL Server vNext on Linux.
In part one, we reviewed the prerequisites required for installing SQL Server vNext. In this part we will explore how to install Microsoft's SQL Server on Ubuntu 16.04.
This video shows, step by step, how to configure Oracle Heterogeneous Services via the Generic Gateway Agent in order to make a connection from an Oracle session and access a remote SQL Server database table.
Via a live example combined with referencing Books Online, show some of the information that can be extracted from the Catalog Views in SQL Server.

971 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question