Solved

Get hour only from DateTime ms sql convert to int

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

NFR key for Veeam Backup for Microsoft Office 365

Veeam is happy to provide a free NFR license (for 1 year, up to 10 users). This license allows for the non‑production use of Veeam Backup for Microsoft Office 365 in your home lab without any feature limitations.

Question has a verified solution.

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

In this article I will describe the Backup & Restore method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
Use this article to create a batch file to backup a Microsoft SQL Server database to a Windows folder.  The folder can be on the local hard drive or on a network share.  This batch file will query the SQL server to get the current date & time and wi…
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.
Viewers will learn how to use the SELECT statement in SQL to return specific rows and columns, with various degrees of sorting and limits in place.

791 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