473,395 Members | 1,987 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

DCount distinct date/time based on date only

Hi I'm trying to Dcount *unique* records by comparing a date/time
field. I say *unique* because the field contains a date/time but I
need to ignore the timestamp and work off the date only.

I think the code below should work to count unique values in a normal
text field but the date/time is causing a lot of problems because it's
reading the timestamps to be different despite the "medium date"
formatting.

DCount("[classdate]", "attendance", "classdate IN ( SELECT
FIRST(classdate) FROM attendance GROUP BY classdate)")
Anyone got any ideas?
Thanks,
Ciarán
Sep 26 '08 #1
3 5916
Cron wrote:
Hi I'm trying to Dcount *unique* records by comparing a date/time
field. I say *unique* because the field contains a date/time but I
need to ignore the timestamp and work off the date only.

I think the code below should work to count unique values in a normal
text field but the date/time is causing a lot of problems because it's
reading the timestamps to be different despite the "medium date"
formatting.

DCount("[classdate]", "attendance", "classdate IN ( SELECT
FIRST(classdate) FROM attendance GROUP BY classdate)")
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Don't use FIRST() & LAST() 'cuz they don't work the way most people
think they are supposed to. Try the DateValue() function if you want to
get just the date part of a DateTime value:

DCount("[classdate]", "attendance", "classdate = " &
DateValue(date_variable) )

Where the "date_variable" is an actual date value or a DateTime data
type variable.

If you want to find the the earliest date use the MIN() function. If
you want to find the latest date use the MAX() function. You'll have to
use a SELECT statement when using the MIN/MAX functions:

SELECT MIN(classdate) As EarliestClass FROM Attendance

or

SELECT MIN(DateValue(classdate)) As EarliestClass FROM Attendance

--
MGFoster:::mgf00 <atearthlink <decimal-pointnet
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/AwUBSNxcGoechKqOuFEgEQJG8QCeOxgVZK79uJum6LCbaWfLTc poGuoAoOdp
djd+0zDtnRw1fCNYmipATYyq
=4XNu
-----END PGP SIGNATURE-----
Sep 26 '08 #2

Thanks for the reply MG but that's not really what I'm trying to
do....
Ok I've figured out how to return distinct datetime results based on
the day:
SELECT DISTINCT Format(classdate, 'mm/dd/yyyy') as class_date FROM
attendance

Now can anyone tell me how to get this into a Dcount function for VBA?
I was hoping this would work but access doesn't like a query in the
domain paramater:
DCount("classdate", "SELECT DISTINCT Format(classdate, 'mm/dd/yyyy')
as class_date FROM attendance", "")

Thanks a lot,
Ciarán
Sep 26 '08 #3
If anyone's interested in my solution to this problem, I ended up
saving the statement above as a query and then counting the results it
generates with the DCount function from VBA.

Ciarán
Sep 30 '08 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Alex Satrapa | last post by:
I have a table from which I'm trying to extract certain information. For historical reasons, we archive every action on a particular thing ('thing' is identified, funnily enough, by 'id'). So the...
4
by: Classified | last post by:
Hey There, Have a problem, hopefully someone out here can lend me a hand. Working on an appointment databases, haven't used VBA in ages and I am find a lot of rust everywhere. What I'm...
7
by: jdph40 | last post by:
I posted this problem previously and received excellent help from Wayne Morgan. However, I still have an unanswered question. My form (frmVacationWeeks) is opened from the OnClick event of a...
1
by: Megan | last post by:
Hi Everybody- I've been reading some of the posts about DCOUNT, and I haven't yet found an answer; so, I'm posting this question. I have a report that I'm trying to use DCOUNT on to compute...
6
by: Mike Conklin | last post by:
This one really has me going. Probably something silly. I'm using dcount for a report to determine the number of different types of tests proctored in a semester. My report is based on a...
6
by: jstaggs39 | last post by:
I want to create a Dcount and an If...Then...Else statement to count the number of records in a table based on the date that is entered to run the form. The If....Else statment comes in because if...
3
by: ringer | last post by:
I am trying to add a functionality into a db I use for my checkbook that will help me plan for and save money for future large expenses. Into a table called tblFutureTransactions I want to enter...
36
by: bmyers | last post by:
Good afternoon, I am attempting to count only those records within a report, which is based on a query, where Status is equal to Closed. I have tried multiple variations of DCOUNT but am...
4
by: 6afraidbecause789 | last post by:
I was able to glean syntax online for a DCount on a form that counts the number of 'misbehavior' incidents for students for the current day: =DCount("StudentID","Incidents","StudentID=" & Forms!...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.