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 |
|
esthera
Master Smack Fu Yak Hacker
1410 Posts |
Posted - 2005-09-12 : 04:31:34
|
| I have a datetimefield called mydateHow could I select all users that the mydate in the user table is within the hour?How can I select all within the last 10 minutes? |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2005-09-12 : 04:54:43
|
| Try these1 Select columns from yourTable where datediff(mi,datecol,getdate()) between 0 and 602 Select columns from yourTable where datediff(mi,datecol,getdate()) between 0 and 10MadhivananFailing to plan is Planning to fail |
 |
|
|
esthera
Master Smack Fu Yak Hacker
1410 Posts |
Posted - 2005-09-12 : 05:01:21
|
| what should mi be? |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2005-09-12 : 05:09:40
|
| It refers minutesDid you get the result you wanted?MadhivananFailing to plan is Planning to fail |
 |
|
|
esthera
Master Smack Fu Yak Hacker
1410 Posts |
Posted - 2005-09-12 : 05:10:11
|
| never mind I assume it's syntax i'm not familiar with as the statement works....I wasn't sure if it was a value I needed to put in.thanks for your help |
 |
|
|
Kristen
Test
22859 Posts |
Posted - 2005-09-12 : 07:53:36
|
| You can use "minute" instead of "mi" - I prefer that because I think it makes the syntax more readable - particularly the subtle differences between d, dd and dy which "Day" and "dayofyear" avoid ... not to mention yy, yyy [which are "year"] but "y" is "dayofyear" again ... and in case "m" might be confused as Month, Minute or even Millisecond ...Kristen |
 |
|
|
|
|
|