Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
EvilTadpole
Starting Member
9 Posts |
Posted - 2005-06-16 : 16:01:43
|
Is there a way to do time calculations from a smalldatetime field. I'm trying to do an hourly feed to our mainframe and I need to find all the rows that were updated in the last hour to feed over. I know that for getdate() if you subtract 1 that removes a day, but is there a similar solution for minutes or hours?ThanksErika |
|
|
dupati1
Posting Yak Master
123 Posts |
Posted - 2005-06-16 : 16:08:00
|
| yes...Look for DateDiff() function...Thanks |
 |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
Posted - 2005-06-16 : 16:08:42
|
| Yes, use DATEADD function. You can add days, months, years, seconds, minutes, etc... to a date. And if you use negative values, you are able to subtract as well.When you do GETDATE() - 1, you are actually using DATEADD.Take a look at the DATEADD function in SQL Server Books Online for more details.Tara |
 |
|
|
EvilTadpole
Starting Member
9 Posts |
Posted - 2005-06-16 : 16:23:08
|
| First, thanks Dupati1, that was what I was looking for. I didn't get as far as looking for the DateDiff() function because I was having no luck with other functions, but now I know it handles time too!!Second, Tara, thanks for the response. I use 'select getdate() - 1' just to find the previous date, but actually I tend to use it more in conversion funtions like convert(char, getdate() - 1, 112) to compare with previous day data (Mainfram dates are in international for us)Thanks guys! |
 |
|
|
|
|
|
|
|