Friday, February 24, 2012

Datepart query example help needed or something else?

The field itemdate is a datetime field in sqlserver2000 DB

This works fine:
Select Id From BookData Where (MONTH(itemdate) = '01') and
(DAY(itemdate) = '02') and (YEAR(itemdate) = '2005') order by
TitleDuplicate

This does not work:
Select Id From BookData Where (MONTH(itemdate) = '01') and
(DAY(itemdate) = '02') and (YEAR(itemdate) = '2005') and (datepart(Hh,
itemdate) = '06') and (datepart(Mi, itemdate) = '17') and (datepart(Ss,
itemdate) = '15') order by TitleDuplicate

It returns zero records even though the datetime field has a record
with the datetime value in it of:
1/2/2005 6:17:15 PM

I tried a bunch of different things like datepart(hh,itemdate) ='6'"
etc...

the DB script for this datetime field sets it as:
"ItemDate DATETIME DEFAULT '',"

Any ideas on what is going on or what am I missing ?
Thanks for any help you can give.Where convert(varchar(8),itemdate,112) = '20050102'
and convert(varchar(8),itemdate,108) = '06:17:15'

Note - the datepart valuse you have are int's not chars.

Nigel Rivett
www.nigelrivett.net

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!|||It is solved!
My own fault for not thinking of a 24 hour clock.
The hours I should have tried was 18 not 6 . I was thinking 6 AM when
it was 6
PM. It really had me bugged out
The code was working all along.

No comments:

Post a Comment