Solved

Get hour only from DateTime ms sql convert to int

Posted on 2011-03-11
5
1,182 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 142

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 500 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 142

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

U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.

Question has a verified solution.

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

The Delta outage: 650 cancelled flights, more than 1200 delayed flights, thousands of frustrated customers, tens of millions of dollars in damages – plus untold reputational damage to one of the world’s most trusted airlines. All due to a catastroph…
I have a large data set and a SSIS package. How can I load this file in multi threading?
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
Via a live example, show how to extract information from SQL Server on Database, Connection and Server properties

930 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now