• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1289
  • Last Modified:

Get hour only from DateTime ms sql convert to int

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
QuinnDester
Asked:
QuinnDester
  • 3
  • 2
1 Solution
 
Guy Hengel [angelIII / a3]Billing EngineerCommented:
DATEPART(hour, yourfield)
0
 
QuinnDesterAuthor Commented:
Thank you, works like a charm,
0
 
QuinnDesterAuthor Commented:
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
 
Guy Hengel [angelIII / a3]Billing EngineerCommented:
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
 
QuinnDesterAuthor Commented:
thank you....  your a life saver :)
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

The 14th Annual Expert Award Winners

The results are in! Meet the top members of our 2017 Expert Awards. Congratulations to all who qualified!

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now