Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

SQL GETDATE

Status
Not open for further replies.

Khanson82

MIS
Mar 5, 2010
85
US
Im trying to get all records that are >= (previous day at noon)

This would seem easy but not so much for me.....

Our dates are stored like '1995-01-01 00:00:00.000'
The time is in military units.(0-24)


Any ideas?

Thanks again..
 
First you would need to convert your dates to datetime with
dateadd(hour, HourCol, DateCol) and then you will be able to compare with

dateadd(hour,12,dateadd(day,-1+datediff(day,'20100101',getdate()),'20100101') -- this should give you previous day at noon

However, perhaps it makes sense to add persisted computed column to your table based on the above, index on it and use that column instead of functions if these types of queries are often enough.




PluralSight Learning Library
 
That worked..All i needed was your getdate expression, since my original column is datetime already too..
Thanks again!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top