Friday, February 24, 2012

Date Field problem

Hi All,

I have the following query , it is getting values of 6th months also
Actually i want only values between the dates...
nt_date is datetime field

select CONVERT(varchar(10), nt_date, 103) from empdate
where CONVERT(varchar(10), nt_date, 103) between '01/05/2003' and '10/05/2003'

my idea of the above query is that it has to display only
records between 01/05 to 10/05

Thanksyou should do the WHERE comparison in date format, not in string format --
select CONVERT(varchar(10), nt_date, 103)
from empdate
where nt_date between '2003-05-01' and '2003-05-10'
the reason yours wasn't working is because using a string comparison, '09/03/1937' would fall between '01/05/2003' and '10/05/2003'

No comments:

Post a Comment