Results 1 to 3 of 3
  1. #1
    jtan is offline Novice
    Windows XP Access 2010 32bit
    Join Date
    Nov 2013
    Location
    Singapore
    Posts
    22

    DCount the number of holidays between 2 dates

    Hi all,

    Need your help on below problem.
    Below tbl_Holidays for all holiday dates in Singapore.
    HolidayDate Remark
    01-Jan-20 New Year Day
    27-Jan-20 Chinese New Year Replacement
    10-Apr-20 Good Friday
    01-May-20 Labour Day
    07-May-20 Vesak Day
    25-May-20 Hari Raya Puasa Replacement
    31-Jul-20 Hari Raya Haji
    10-Aug-20 National Day Replacement
    25-Dec-20 Christmas


    and below query to count the number of holidays between 2 dates (ReceivedDate and InspectedDate)
    NoOfHolidays: DCount("*","tbl_Holidays","[HolidayDate] BETWEEN #" & [ReceivedDate] & "# AND #" & [InspectedDate] & "#")




    But, below query result (highlighted) is not correct. The correct NoOfHolidays is 1.
    ReceivedDate InspectedDate NoOfHolidays
    02-Apr-20 13-Apr-20 1
    02-Apr-20 15-Apr-20 1
    03-Apr-20 13-Apr-20 1
    03-Apr-20 16-Apr-20 1
    03-Apr-20 20-Apr-20 1
    06-Apr-20 13-Apr-20 3
    06-Apr-20 15-Apr-20 3
    06-Apr-20 20-Apr-20 3
    07-Apr-20 13-Apr-20 3
    08-Apr-20 13-Apr-20 4
    08-Apr-20 15-Apr-20 4
    08-Apr-20 16-Apr-20 4
    09-Apr-20 13-Apr-20 5
    09-Apr-20 20-Apr-20 5


    Can someone advise what is wrong ?
    Appreciate your help
    Attached Thumbnails Attached Thumbnails Query.jpg  

  2. #2
    June7's Avatar
    June7 is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,930
    Query syntax and DCount() work for me.

    Issue might be with international date. Review http://allenbrowne.com/ser-36.html
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    CJ_London is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,430
    it is because your dates need to be formatted as 'mm/dd/yyyy' (US style). At the moment it is interpreting 6th April as 4th June. The interpreter is good enough to know that there are only 12 months so interprets 13th April correctly

    try

    NoOfHolidays: DCount("*","tbl_Holidays","[HolidayDate] BETWEEN #" & format([ReceivedDate],"mm/dd/yyyy") & "# AND #" & format([InspectedDate],"mm/dd/yyyy") & "#")

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 36
    Last Post: 05-10-2018, 02:02 PM
  2. Replies: 1
    Last Post: 04-20-2015, 04:17 PM
  3. DCount between dates - Please Help :)
    By basacwards in forum Forms
    Replies: 1
    Last Post: 12-04-2014, 09:18 AM
  4. DCount only counting some dates
    By Jules48 in forum Programming
    Replies: 7
    Last Post: 09-22-2011, 02:29 AM
  5. Holidays falling between dates
    By Alex Motilal in forum Queries
    Replies: 1
    Last Post: 11-15-2010, 11:59 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums