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.

 All Forums
 SQL Server 2000 Forums
 Transact-SQL (2000)
 query date by hour

Author  Topic 

esthera
Master Smack Fu Yak Hacker

1410 Posts

Posted - 2005-09-12 : 04:31:34
I have a datetimefield called mydate

How 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 these

1 Select columns from yourTable where datediff(mi,datecol,getdate()) between 0 and 60

2 Select columns from yourTable where datediff(mi,datecol,getdate()) between 0 and 10


Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

esthera
Master Smack Fu Yak Hacker

1410 Posts

Posted - 2005-09-12 : 05:01:21
what should mi be?
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2005-09-12 : 05:09:40
It refers minutes
Did you get the result you wanted?

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

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
Go to Top of Page

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
Go to Top of Page
   

- Advertisement -