date based query fails to find records in given period

D

danatafl

Access 2007. I have a query that groups records into a time period: p1 is 1
minute past midnight to 6am, p2 is 6:01am to noon, p3 is 1 minute past noon
to 6pm and p4 is 6:01pm to midnight (SQL below).

For some reason, I get no records for period 3. I have tried all sorts of
combinations (12 and 24 hour clock, dateadd (+ve and -ve variations)) all
without success. If I vary the time between 12:01 and 12:59 I still get
nothing in this period. If I restrict the range to 1:01 pm to 6pm records are
returned (so there are records in the range).

I am missing some silly mistake somewhere or there is something else going
on.

Period: IIf([real_entry_time] Between #12:01:00 a.m.# And #6:00:00
a.m.#,"p1_00:01 to 06:00",IIf([real_entry_time] Between #6:01:00 a.m.# And
#12:00:00 p.m.#,"p2_06:01 to 12:00",IIf([real_entry_time] Between #12:01:00
p.m.# And #6:00:00 p.m.#,"p3_12:01 to 18:00","p4_18:01 to 00:00")))

Thank you for your time.
 
A

Allen Browne

Is there any chance that the records in your table contain a date as well as
a time? (The date part may not show up if the Format is Short Time or
similar.)

If that is not the issue, declare the parameter.
Choose Parameters on the Query menu in query design view.
Access opens a dialog.
Enter:
[real_entry_time] Date

(This assumes the field you placed this expression under is a Date/Time
field, not a Text field.)
 
D

danatafl

I'm sorry, I don't understand how this would help. real_entery_time is a
field on the table not a parameter. The field holds a time only (populated
from a date/time field using format function and hh:nn format option). I
tried anyway but all that happened was that I was prompted for the new
parameter value and was still missing period three records.

Allen Browne said:
Is there any chance that the records in your table contain a date as well as
a time? (The date part may not show up if the Format is Short Time or
similar.)

If that is not the issue, declare the parameter.
Choose Parameters on the Query menu in query design view.
Access opens a dialog.
Enter:
[real_entry_time] Date

(This assumes the field you placed this expression under is a Date/Time
field, not a Text field.)

--
Allen Browne - Microsoft MVP. Perth, Western Australia

Reply to group, rather than allenbrowne at mvps dot org.

danatafl said:
Access 2007. I have a query that groups records into a time period: p1 is
1
minute past midnight to 6am, p2 is 6:01am to noon, p3 is 1 minute past
noon
to 6pm and p4 is 6:01pm to midnight (SQL below).

For some reason, I get no records for period 3. I have tried all sorts of
combinations (12 and 24 hour clock, dateadd (+ve and -ve variations)) all
without success. If I vary the time between 12:01 and 12:59 I still get
nothing in this period. If I restrict the range to 1:01 pm to 6pm records
are
returned (so there are records in the range).

I am missing some silly mistake somewhere or there is something else going
on.

Period: IIf([real_entry_time] Between #12:01:00 a.m.# And #6:00:00
a.m.#,"p1_00:01 to 06:00",IIf([real_entry_time] Between #6:01:00 a.m.# And
#12:00:00 p.m.#,"p2_06:01 to 12:00",IIf([real_entry_time] Between
#12:01:00
p.m.# And #6:00:00 p.m.#,"p3_12:01 to 18:00","p4_18:01 to 00:00")))

Thank you for your time.
 
D

danatafl

I tried this but as soon as I exit the qbe field, the format reverts to
"a.m." or "p.m."

Gina Whipp said:
Try changing a.m to AM and p.m. to PM...

--
Gina Whipp

"I feel I have been denied critical, need to know, information!" - Tremors
II

danatafl said:
Access 2007. I have a query that groups records into a time period: p1 is
1
minute past midnight to 6am, p2 is 6:01am to noon, p3 is 1 minute past
noon
to 6pm and p4 is 6:01pm to midnight (SQL below).

For some reason, I get no records for period 3. I have tried all sorts of
combinations (12 and 24 hour clock, dateadd (+ve and -ve variations)) all
without success. If I vary the time between 12:01 and 12:59 I still get
nothing in this period. If I restrict the range to 1:01 pm to 6pm records
are
returned (so there are records in the range).

I am missing some silly mistake somewhere or there is something else going
on.

Period: IIf([real_entry_time] Between #12:01:00 a.m.# And #6:00:00
a.m.#,"p1_00:01 to 06:00",IIf([real_entry_time] Between #6:01:00 a.m.# And
#12:00:00 p.m.#,"p2_06:01 to 12:00",IIf([real_entry_time] Between
#12:01:00
p.m.# And #6:00:00 p.m.#,"p3_12:01 to 18:00","p4_18:01 to 00:00")))

Thank you for your time.
 
J

John W. Vinson

Access 2007. I have a query that groups records into a time period: p1 is 1
minute past midnight to 6am, p2 is 6:01am to noon, p3 is 1 minute past noon
to 6pm and p4 is 6:01pm to midnight (SQL below).

For some reason, I get no records for period 3. I have tried all sorts of
combinations (12 and 24 hour clock, dateadd (+ve and -ve variations)) all
without success. If I vary the time between 12:01 and 12:59 I still get
nothing in this period. If I restrict the range to 1:01 pm to 6pm records are
returned (so there are records in the range).

I am missing some silly mistake somewhere or there is something else going
on.

Period: IIf([real_entry_time] Between #12:01:00 a.m.# And #6:00:00
a.m.#,"p1_00:01 to 06:00",IIf([real_entry_time] Between #6:01:00 a.m.# And
#12:00:00 p.m.#,"p2_06:01 to 12:00",IIf([real_entry_time] Between #12:01:00
p.m.# And #6:00:00 p.m.#,"p3_12:01 to 18:00","p4_18:01 to 00:00")))

Thank you for your time.

I'd try the Switch() function instead:

Switch([real_entry_time] < #06:00#, "p1_00:01 to 6:00",
[real_entry_time] < #12:00#, "p2_06:01 to 12:00",
[real_entry_time] < #18:00#, "p3_12:01 to 18:00",'
True, "p4_18:01 to 00:00")

The Switch function takes arguments in pairs, returning the second of the pair
when it first finds a True value in the first.

If [real_entry_time] actually contains a date and time, use

TimeValue([real_entry_time])

in each case.

Note that a Date/TIme value is stored as a double float count of days and
fractions of a day since midnight, December 30, 1899. Therefore #06:00# is
actually stored as 0.25 and is actually #12/30/1899 06:00#.
 
M

MGFoster

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Don't put periods in the AM & PM indicators. E.g.:

#12:01:00 AM#

--
MGFoster:::mgf00 <at> earthlink <decimal-point> net
Oakland, CA (USA)
** Respond only to this newsgroup. I DO NOT respond to emails **

-----BEGIN PGP SIGNATURE-----
Version: PGP for Personal Privacy 5.0
Charset: noconv

iQA/AwUBST3xEIechKqOuFEgEQIbwgCfYOQ7CxhWoZyncy11bYdaBJk2oPAAn335
sZxNNONo9+JCktR3kaULob1f
=SNN8
-----END PGP SIGNATURE-----
 
G

Gina Whipp

Period: IIf([real_entry_time] Between #12:01:00 AM# And #06:00:00
AM#,"p1_00:01 to 06:00",IIf([real_entry_time] Between #06:01:00 AM# And
#12:00:00 PM#,"p2_06:01 to 12:00",IIf([real_entry_time] Between #12:01:00
PM# And #06:00:00 PM#,"p3_12:01 to 18:00","p4_18:01 to 00:00")))

I got the above to work for those times you specified. Are you sure it's a
Date/Time field you are querying on? Of course, I can't get anything to
work if I use a dot m dot, I have to remove the dots.
--
Gina Whipp

"I feel I have been denied critical, need to know, information!" - Tremors
II
danatafl said:
I tried this but as soon as I exit the qbe field, the format reverts to
"a.m." or "p.m."

Gina Whipp said:
Try changing a.m to AM and p.m. to PM...

--
Gina Whipp

"I feel I have been denied critical, need to know, information!" -
Tremors
II

danatafl said:
Access 2007. I have a query that groups records into a time period: p1
is
1
minute past midnight to 6am, p2 is 6:01am to noon, p3 is 1 minute past
noon
to 6pm and p4 is 6:01pm to midnight (SQL below).

For some reason, I get no records for period 3. I have tried all sorts
of
combinations (12 and 24 hour clock, dateadd (+ve and -ve variations))
all
without success. If I vary the time between 12:01 and 12:59 I still get
nothing in this period. If I restrict the range to 1:01 pm to 6pm
records
are
returned (so there are records in the range).

I am missing some silly mistake somewhere or there is something else
going
on.

Period: IIf([real_entry_time] Between #12:01:00 a.m.# And #6:00:00
a.m.#,"p1_00:01 to 06:00",IIf([real_entry_time] Between #6:01:00 a.m.#
And
#12:00:00 p.m.#,"p2_06:01 to 12:00",IIf([real_entry_time] Between
#12:01:00
p.m.# And #6:00:00 p.m.#,"p3_12:01 to 18:00","p4_18:01 to 00:00")))

Thank you for your time.
 
A

Allen Browne

Sorry: I did misunderstand your example.

Try:
Hour([real_entry_time]) \ 6

That should yield a number between 0 and 3.

--
Allen Browne - Microsoft MVP. Perth, Western Australia

Reply to group, rather than allenbrowne at mvps dot org.

danatafl said:
I'm sorry, I don't understand how this would help. real_entery_time is a
field on the table not a parameter. The field holds a time only (populated
from a date/time field using format function and hh:nn format option). I
tried anyway but all that happened was that I was prompted for the new
parameter value and was still missing period three records.

Allen Browne said:
Is there any chance that the records in your table contain a date as well
as
a time? (The date part may not show up if the Format is Short Time or
similar.)

If that is not the issue, declare the parameter.
Choose Parameters on the Query menu in query design view.
Access opens a dialog.
Enter:
[real_entry_time] Date

(This assumes the field you placed this expression under is a Date/Time
field, not a Text field.)

danatafl said:
Access 2007. I have a query that groups records into a time period: p1
is
1
minute past midnight to 6am, p2 is 6:01am to noon, p3 is 1 minute past
noon
to 6pm and p4 is 6:01pm to midnight (SQL below).

For some reason, I get no records for period 3. I have tried all sorts
of
combinations (12 and 24 hour clock, dateadd (+ve and -ve variations))
all
without success. If I vary the time between 12:01 and 12:59 I still get
nothing in this period. If I restrict the range to 1:01 pm to 6pm
records
are
returned (so there are records in the range).

I am missing some silly mistake somewhere or there is something else
going
on.

Period: IIf([real_entry_time] Between #12:01:00 a.m.# And #6:00:00
a.m.#,"p1_00:01 to 06:00",IIf([real_entry_time] Between #6:01:00 a.m.#
And
#12:00:00 p.m.#,"p2_06:01 to 12:00",IIf([real_entry_time] Between
#12:01:00
p.m.# And #6:00:00 p.m.#,"p3_12:01 to 18:00","p4_18:01 to 00:00")))
 
D

danatafl

Timevalue worked so I guess the data was not being recognised appropriately
for some reason. Thank you also for introducing me to switch.

John W. Vinson said:
Access 2007. I have a query that groups records into a time period: p1 is 1
minute past midnight to 6am, p2 is 6:01am to noon, p3 is 1 minute past noon
to 6pm and p4 is 6:01pm to midnight (SQL below).

For some reason, I get no records for period 3. I have tried all sorts of
combinations (12 and 24 hour clock, dateadd (+ve and -ve variations)) all
without success. If I vary the time between 12:01 and 12:59 I still get
nothing in this period. If I restrict the range to 1:01 pm to 6pm records are
returned (so there are records in the range).

I am missing some silly mistake somewhere or there is something else going
on.

Period: IIf([real_entry_time] Between #12:01:00 a.m.# And #6:00:00
a.m.#,"p1_00:01 to 06:00",IIf([real_entry_time] Between #6:01:00 a.m.# And
#12:00:00 p.m.#,"p2_06:01 to 12:00",IIf([real_entry_time] Between #12:01:00
p.m.# And #6:00:00 p.m.#,"p3_12:01 to 18:00","p4_18:01 to 00:00")))

Thank you for your time.

I'd try the Switch() function instead:

Switch([real_entry_time] < #06:00#, "p1_00:01 to 6:00",
[real_entry_time] < #12:00#, "p2_06:01 to 12:00",
[real_entry_time] < #18:00#, "p3_12:01 to 18:00",'
True, "p4_18:01 to 00:00")

The Switch function takes arguments in pairs, returning the second of the pair
when it first finds a True value in the first.

If [real_entry_time] actually contains a date and time, use

TimeValue([real_entry_time])

in each case.

Note that a Date/TIme value is stored as a double float count of days and
fractions of a day since midnight, December 30, 1899. Therefore #06:00# is
actually stored as 0.25 and is actually #12/30/1899 06:00#.
 

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