Click to See Complete Forum and Search --> : Insert System Date into query automatically


skier500000
07-17-2009, 02:53 PM
I have an access query that I want to automatically insert the system date into for Start Date and End Date so it will query automatically query only for records that were entered today.

I am currently prompting the user to enter the date manually e.g. Enter Start Date and Enter End Date with the following criteria;

Between [Enter Start Date] And [Enter End Date]

Can this be done?

Hack
07-20-2009, 07:34 AM
UseFormat(Now, "mm/dd/yyyy")

Ron Weller
07-20-2009, 11:10 AM
Now() includes date and time, so Format(Now, "mm/dd/yyyy") strips off the time part; but you could just use Date() which only returns the date, no time part.
In your query, you are using Between, but if you are only looking for one day then you don't need Between which requires both a start and end value. Just change the criteria to Date()

tkorsano
07-29-2009, 06:32 PM
To be short, I just thought:

where date_field_in_table between date() and dateadd("d", 1, date())

just maybe, it could be:

where date_column_in_table between Format(Now, "mm/dd/yyyy") and dateadd("d", 1, Format(Now, "mm/dd/yyyy"))

one of this two might work.

if you want between right now and the next 24 hours

where date_column_in_table between now and dateadd("h", 24, now)

this last one should be a pretty good approximation.

Best regards,

Tonci Korsano