Home All Groups Group Topic Archive Search About

How to query for "today's" records?

Author
27 May 2005 11:41 PM
Martin
In my VB6 program, I'm executing a query against an MS Access database
in which I want to return all records which have a specified date in a
date field. The problem is, if I say: ...WHERE MyDate = #5/27/05# then
I get no records because the date field contains the date AND the time
and thus is not exactly equal to #5/27/05#.

How can I write the WHERE clause so that I get all of the day's
records no matter what the time on them is?

Thanks.

Author
28 May 2005 12:30 AM
Andrew D. Newbould
In message <tjbf915fjq1hsf43ql2r5k376215of8***@4ax.com>, Martin
<martinval***@comcast.net> writes
>In my VB6 program, I'm executing a query against an MS Access database
>in which I want to return all records which have a specified date in a
>date field. The problem is, if I say: ...WHERE MyDate = #5/27/05# then
>I get no records because the date field contains the date AND the time
>and thus is not exactly equal to #5/27/05#.
>
>How can I write the WHERE clause so that I get all of the day's
>records no matter what the time on them is?
>
>Thanks.

WHERE MyDate BETWEEN #2005-05-27 00:00:00# AND #2005-05-27 23:59:59#

--
Andrew D. Newbould                  E-Mail:  newsgroups@NOSPAMzadsoft.com

ZAD Software Systems                Web   :  www.zadsoft.com
Author
28 May 2005 12:57 PM
Martin
On Sat, 28 May 2005 01:30:29 +0100, "Andrew D. Newbould"
<newsgro***@NOzadSPANsoft.com> wrote:

Show quoteHide quote
>In message <tjbf915fjq1hsf43ql2r5k376215of8***@4ax.com>, Martin
><martinval***@comcast.net> writes
>>In my VB6 program, I'm executing a query against an MS Access database
>>in which I want to return all records which have a specified date in a
>>date field. The problem is, if I say: ...WHERE MyDate = #5/27/05# then
>>I get no records because the date field contains the date AND the time
>>and thus is not exactly equal to #5/27/05#.
>>
>>How can I write the WHERE clause so that I get all of the day's
>>records no matter what the time on them is?
>>
>>Thanks.
>
>WHERE MyDate BETWEEN #2005-05-27 00:00:00# AND #2005-05-27 23:59:59#

Thanks, that works.

But, I thought maybe there was a built-in function that returned just
the date portion of the date/time value. No?
Author
28 May 2005 3:04 PM
Norm Cook
Here's one way:
Dim d As Date
d = #5/27/2005 11:59:58 PM#
Debug.Print DateSerial(Year(d), Month(d), Day(d))
Debug.Print TimeSerial(Hour(d), Minute(d), Second(d))

Show quoteHide quote
"Martin" <martinval***@comcast.net> wrote in message
news:3gqg91da8utg352t1e93375sndcv1kjnoa@4ax.com...
> On Sat, 28 May 2005 01:30:29 +0100, "Andrew D. Newbould"
> <newsgro***@NOzadSPANsoft.com> wrote:
>
> >In message <tjbf915fjq1hsf43ql2r5k376215of8***@4ax.com>, Martin
> ><martinval***@comcast.net> writes
> >>In my VB6 program, I'm executing a query against an MS Access database
> >>in which I want to return all records which have a specified date in a
> >>date field. The problem is, if I say: ...WHERE MyDate = #5/27/05# then
> >>I get no records because the date field contains the date AND the time
> >>and thus is not exactly equal to #5/27/05#.
> >>
> >>How can I write the WHERE clause so that I get all of the day's
> >>records no matter what the time on them is?
> >>
> >>Thanks.
> >
> >WHERE MyDate BETWEEN #2005-05-27 00:00:00# AND #2005-05-27 23:59:59#
>
> Thanks, that works.
>
> But, I thought maybe there was a built-in function that returned just
> the date portion of the date/time value. No?
Author
29 May 2005 3:49 PM
Martin
I was thinking more along the line of a function that would extract
the date part of the value stored in the MDB record which could then
be compared to a given date string. Like:

WHERE TheDateOnly(MyDate) = #5/27/05#

I looked in to the DatePart function but it seems to return either the
Month, the Day or the Year (but not a combination of the three).

Oh well, the original suggestion does what I needed to do.

Martin

On Sat, 28 May 2005 10:04:54 -0500, "Norm Cook"
<normcookNOSPAM@cableone.net> wrote:

Show quoteHide quote
>Here's one way:
> Dim d As Date
> d = #5/27/2005 11:59:58 PM#
> Debug.Print DateSerial(Year(d), Month(d), Day(d))
> Debug.Print TimeSerial(Hour(d), Minute(d), Second(d))
>
>"Martin" <martinval***@comcast.net> wrote in message
>news:3gqg91da8utg352t1e93375sndcv1kjnoa@4ax.com...
>> On Sat, 28 May 2005 01:30:29 +0100, "Andrew D. Newbould"
>> <newsgro***@NOzadSPANsoft.com> wrote:
>>
>> >In message <tjbf915fjq1hsf43ql2r5k376215of8***@4ax.com>, Martin
>> ><martinval***@comcast.net> writes
>> >>In my VB6 program, I'm executing a query against an MS Access database
>> >>in which I want to return all records which have a specified date in a
>> >>date field. The problem is, if I say: ...WHERE MyDate = #5/27/05# then
>> >>I get no records because the date field contains the date AND the time
>> >>and thus is not exactly equal to #5/27/05#.
>> >>
>> >>How can I write the WHERE clause so that I get all of the day's
>> >>records no matter what the time on them is?
>> >>
>> >>Thanks.
>> >
>> >WHERE MyDate BETWEEN #2005-05-27 00:00:00# AND #2005-05-27 23:59:59#
>>
>> Thanks, that works.
>>
>> But, I thought maybe there was a built-in function that returned just
>> the date portion of the date/time value. No?
>
Author
29 May 2005 5:33 PM
John Cleveland
"Martin" <martinval***@comcast.net> wrote in message
news:rnoj9115j9kkqmflevn84ct8h9b55a6air@4ax.com...
>I was thinking more along the line of a function that would extract
> the date part of the value stored in the MDB record which could then
> be compared to a given date string. Like:
>
> WHERE TheDateOnly(MyDate) = #5/27/05#

Have you tried the Format function?
Format(MyDate, "mm/dd/yy")