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 2005 Forums
 Transact-SQL (2005)
 date and time problem

Author  Topic 

habuzahra
Starting Member

1 Post

Posted - 2007-05-08 : 09:04:07
Dear All i have a datetime field in the database which store the date and time in the following format :

2007-05-08 22:10:00

i have the following query :

select distinct users.userName, users.fullname, users.primaryemail, users.simulated
from dbo.users,dbo.AuditTrail
where users.userid = AuditTrail.userid
and AuditTrail.audittypeid =1 and AuditTrail.DateTime
between '2007-04-25 00:00:00'
and '2007-04-25 23:59:59'


The Problem is that when i need to get the records any date
i should write between '2007-04-25 00:00:00' and '2007-04-25 23:59:59'



how i can make it to be like :
where AuditTrail.DateTime= '2007-04-25' so i don't need to add the hours minutes and second


Thanks



SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2007-05-08 : 09:14:37
select distinct users.userName, users.fullname, users.primaryemail, users.simulated
from dbo.users,dbo.AuditTrail
where users.userid = AuditTrail.userid
and AuditTrail.audittypeid =1
and AuditTrail.DateTime >= '20070425'
and AuditTrail.DateTime < '20070426'


Peter Larsson
Helsingborg, Sweden
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2007-05-08 : 10:15:24
http://sql-server-performance.com/fk_datetime.asp for more info on dates

Madhivanan

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

- Advertisement -