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
 General SQL Server Forums
 New to SQL Server Programming
 query using dates.

Author  Topic 

rjhe22
Constraint Violating Yak Guru

283 Posts

Posted - 2009-01-19 : 08:07:33
any ideas why this wont work


select * from dbo.ErrorLog
where ErrorTime = '05-03-2008'

raky
Aged Yak Warrior

767 Posts

Posted - 2009-01-19 : 08:11:27
try this

If u r dateformat is mm-dd-yyyy

select * from dbo.ErrorLog
where convert( varchar(12),ErrorTime,110) = '05-03-2008'

If u r dateformat is dd-mm-yyyy then

use this


select * from dbo.ErrorLog
where convert( varchar(12),ErrorTime,105) = '05-03-2008'
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2009-01-19 : 08:15:41
select * from dbo.ErrorLog
where ErrorTime >= '2008-05-03' -- May 3rd 2008
and ErrorTime < '2008-05-04' -- May 4th 2008



E 12°55'05.63"
N 56°04'39.26"
Go to Top of Page

rjhe22
Constraint Violating Yak Guru

283 Posts

Posted - 2009-01-19 : 08:16:16
perfect cheers
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2009-01-19 : 08:47:25
quote:
Originally posted by rjhe22

any ideas why this wont work


select * from dbo.ErrorLog
where ErrorTime = '05-03-2008'


the reason why it didnt work is because you had timepart along with date value in ErrorTime column.the value 05-03-2008 corresponds to start of day 05-03-2008 which is 12 midnight
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2009-01-19 : 08:55:49
quote:
Originally posted by rjhe22

any ideas why this wont work


select * from dbo.ErrorLog
where ErrorTime = '05-03-2008'


Also you expressed dates in ambiguious format. Use universal format YYYYMMDD

Madhivanan

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

- Advertisement -