Solved

Get hour only from DateTime ms sql convert to int

Posted on 2011-03-11
5
1,185 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 
LVL 143

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 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

In this article we will get to know that how can we recover deleted data if it happens accidently. We really can recover deleted rows if we know the time when data is deleted by using the transaction log.
Load balancing is the method of dividing the total amount of work performed by one computer between two or more computers. Its aim is to get more work done in the same amount of time, ensuring that all the users get served faster.
Via a live example, show how to shrink a transaction log file down to a reasonable size.
Viewers will learn how the fundamental information of how to create a table.

740 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