date part

  • Thread starter Thread starter Sam
  • Start date Start date
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
 
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#
 
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?])
 
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?])
;-)
 
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?])
;-)
 
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

Similar Threads

Is Access 2003 overiding Regional date Settings? 4
Beetle - I Need You Again 17
Help with code 1
Help with code 1
WHats wrong with this query? 4
Access Running Balance in Access 1
suppress 12:00 time 1
Access Count dates within a Month 4

Back
Top