so how would that work in this
IntC = DCount("[CallType]", "dbo_tbl_DailyCall_Log", "[CallType] = 'Inbound' AND DateValue([CallDate]) Between Forms!Retriever![txtDate]AND Forms!Retriever![txtEndDate]")
4. The default date structure for Access is month, day, year. Access can properly interpret text string dates in day, month, year format only when there is no confusion so 13/1/5 would be interpreted as Jan 13. However 12/1/5 would be interpreted as Dec 1. So, the one thing you do NOT want to do is to turn your dates into strings when using them in conditions.
Your not working with a french version of Access or on a french version of Windows!!!
As far as I know, Access uses the Window's regional setting for its prefered date format, but Microsoft Jet uses mm/dd/yyyy no matter what.
I might be wrong...
Originally posted by woknick
I have a Dlookup below:
IntC = DCount("[CallType]", "dbo_tbl_DailyCall_Log", "[CallType] = 'Inbound'AND [CallDate] >= Forms!Retriever![txtDate]AND [CallDate]<= Forms!Retriever![txtEndDate]")
txtDate and txtEndDate is a date in this format: 1/26/2005
unfortunatly [CallType] is a date in this format: 1/26/2005 7:45:00 AM
Since [CallDate] contains also the time, as pointed out by Pat, to return the correct count, you need to use the DateValue() function to extract the dates for comparison.
These two work on both US and UK date systems:-
IntC = DCount("[CallType]", "dbo_tbl_DailyCall_Log", "[CallType] = 'Inbound' AND DateValue([CallDate]) BETWEEN CDATE(Forms!Retriever![txtDate]) AND CDATE(Forms!Retriever![txtEndDate])")
IntC = DCount("[CallType]", "dbo_tbl_DailyCall_Log", "[CallType]='Inbound' AND DateValue([CallDate])>=#" & Format(Forms!Retriever![txtDate], "mm-dd-yyyy") & "# AND DateValue([CallDate])<=#" & Format(Forms!Retriever![txtEndDate], "mm-dd-yyyy") & "#")
This works on systems using US date format:-
IntC = DCount("[CallType]", "dbo_tbl_DailyCall_Log", "[CallType] = 'Inbound' AND DateValue([CallDate]) BETWEEN #" & Forms!Retriever![txtDate] & "# AND #" & Forms!Retriever![txtEndDate] & "#")
They are not the only ones that work. Some other syntax works, too.
Note: By default, Access treats any dates surrounded by the # signs as in US date format. .
I always find the concept of date/time ranges in Access rather difficult to understand.
I noted that DateValue([CallDate]) worked, but I want to know why
WHERE [CallDate] BETWEEN #1/25/2005# AND #1/26/2005# doesn't include the record 1/26/2005 7:45:00 AM
I always find the concept of date/time ranges in Access rather difficult to understand.
I noted that DateValue([CallDate]) worked, but I want to know why
WHERE [CallDate] BETWEEN #1/25/2005# AND #1/26/2005# doesn't include the record 1/26/2005 7:45:00 AM
Because #1/26/2005# actually means #1/26/2005 12:00 AM#. Keep in mind, date values (misnamed, in my opinion; they should be called Datetime values to be more indicative of their nature) are numbers (read Pat's earlier post). The computer converts the dates to numbers for its calculations, so what it is seing is "Between 38373 and 38374". Or, between MIDNIGHT on January 25 2005 to MIDNIGHT January 26 2005. Since 9:00 AM is .375 of one day, January 26, 2005 at 9:00 AM = 38374.375, which is not between 38373 and 38374.
When I do date calculations, I routinely change the date values to a double datatype for ease of understanding, but it is not necessary, as long as you understand the concept of the date values. I am not a big fan of using Between, although others swear by it.
From the results we can see that a datetime value is internally stored as a double precision number, with the integer portion representing the number of days since 12/31/1899 and the decimal portion representing the time of the day since mid-night.
1/25/2005 mid-night is stored as 38377, 1/25/2005 12:00:01 AM as 38377.0000115741,
1/26/2005 mid-night as 38378 and so on.
Hence to execute WHERE [CallDate] BETWEEN #1/25/2005# AND #1/26/2005#
is actually to execute WHERE [CallDate] BETWEEN 38377 AND 38378
Now since any records after 1/26/2005 mid-night are numerically greater than 38378, they would naturally be excluded.
Some people have suggested a solution of adding #23:59:59# to the end date of a date range, or extending the end date of a date range by 1 day but DateAdd() -1 second from it. These suggestions work.
From the third column in the query results we see that Access also has a DateValue() function that can correctly extract the dates from datetime values.
Hence we can do it with either
WHERE [CallDate] BETWEEN #1/25/2005# AND #1/26/2005 23:59:59#
or
WHERE DateValue([CallDate]) BETWEEN #1/25/2005# AND #1/26/2005#
But which one is better?
I think the second one is easier to write and understand. However, running functions does take time. And DateValue([CallDate]) can't take advantage of field index.
Hence, if the table is large, the first one, being without any functions, can obviously run very much faster and is therefore to be preferred. Besides, it can take advantage of field index. .