date part

S

Sam

In a query, I need to select by just the date of a datetime field.
Date=#5/11/09# returns nothing because all the dates have time components.
How can I do this?

Thanks,
Sam
 
M

Marshall Barton

Sam said:
In a query, I need to select by just the date of a datetime field.
Date=#5/11/09# returns nothing because all the dates have time components.


Use the DateValue function.


WHERE DateValue(yourdatetimefield) = #5/11/09#
 
D

Douglas J. Steele

Marshall Barton said:
Use the DateValue function.


WHERE DateValue(yourdatetimefield) = #5/11/09#

Or (perhaps a little more efficient, since it avoids the function call)

WHERE yourdatetimefield BETWEEN #5/11/09# AND #5/12/09#

If you're using a parameter, that would be

WHERE yourdatetimefield BETWEEN [What Day?] AND DateAdd("d", 1, [What Day?])
 
M

Marshall Barton

Douglas said:
"Marshall Barton"wrote
Use the DateValue function.

WHERE DateValue(yourdatetimefield) = #5/11/09#


Or (perhaps a little more efficient, since it avoids the function call)

WHERE yourdatetimefield BETWEEN #5/11/09# AND #5/12/09#

If you're using a parameter, that would be

WHERE yourdatetimefield BETWEEN [What Day?] AND DateAdd("d", 1, [What Day?])


Good idea Doug, but to be very picky, I think it should be

.... BETWEEN #5/11/09# AND #5/11/09 23:59:59#
or
.... BETWEEN [What Day?] AND DateAdd("s", 86399, [What Day?])
;-)
 
S

Sam

really helpful.
Thanks so much.

Marshall Barton said:
Douglas said:
"Marshall Barton"wrote
Sam wrote:
In a query, I need to select by just the date of a datetime field.
Date=#5/11/09# returns nothing because all the dates have time components.


Use the DateValue function.

WHERE DateValue(yourdatetimefield) = #5/11/09#


Or (perhaps a little more efficient, since it avoids the function call)

WHERE yourdatetimefield BETWEEN #5/11/09# AND #5/12/09#

If you're using a parameter, that would be

WHERE yourdatetimefield BETWEEN [What Day?] AND DateAdd("d", 1, [What Day?])


Good idea Doug, but to be very picky, I think it should be

.... BETWEEN #5/11/09# AND #5/11/09 23:59:59#
or
.... BETWEEN [What Day?] AND DateAdd("s", 86399, [What Day?])
;-)
 
J

John W. Vinson

Good idea Doug, but to be very picky, I think it should be

... BETWEEN #5/11/09# AND #5/11/09 23:59:59#
or
... BETWEEN [What Day?] AND DateAdd("s", 86399, [What Day?])
;-)

Or even pickier...
= [What Day?] AND < DateAdd("d", 1, [What Day?])
 

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