By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,265 Members | 1,343 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,265 IT Pros & Developers. It's quick & easy.

Datepart query example help needed or something else??

P: n/a
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

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'"

the DB script for this datetime field sets it as:

Any ideas on what is going on or what am I missing ?
Thanks for any help you can give.

Jul 23 '05 #1
Share this Question
Share on Google+
2 Replies

P: n/a
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

*** Sent via Developersdex ***
Don't just participate in USENET...get rewarded for it!
Jul 23 '05 #2

P: n/a
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.

Jul 23 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.