SQL Date Query Help

J

Jay Villa

Hi

I need to write a query to get the records between two dates. Also I've to
include time criteria.
Startdatetime = '05/'6/2005 10:00 AM' EndDatetime = '07/08/2005 12:00PM'.
I want to get only records for the date specified above between 10:00AM and
12:00PM each day. Only records matchin date and time criteria.....

Thanks
Jay

For example

Select * from table where between startdatetime '05/07/2005 10:00AM'
and '07/08/2005 12:00PM'
Will get all the records ..... even records with time 05/07/2005 01:00PM but
I want each day between 10:00 AM and 12:00PM
 
S

Sylvain Lafontaine

You must extract the Day and the Hour separately with the Convert function,
reconvert these extracted values back into the DateTime format and realize
two Between comparaison. For exemple, to extract the Day only:

convert (DateTime, convert (DateTime, MyDateTimeField, 102), 102)

Or:
convert (DateTime, convert (DateTime, MyDateTimeField, 102) +
'12:00:00 AM', 102)

There is a newsgroup about SQL Server programming: m.p.sqlserver.programming
..
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top