Results 1 to 5 of 5
  1. #1
    TOPSie is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Mar 2021
    Posts
    108

    Date comparison (drives me mad)



    Code:
    If rs!DeliveryDate = wtestdate
    rs!DeliveryDate is a field read from the database defined as Date
    wTestDate is a local variable defined as Date

    execute the code and break in this line
    rs!Feliverydate has a value of 27/09/2023
    wtestdate has a value of 27/09/2023__08:30:00

    the comparison fails.

    All I want to do is check if it is the same Day -the time is irrelvant

    I hate SQL/Access date handling - just when I think I understand it all goes pear shaped again

  2. #2
    Minty is offline VIP
    Windows 10 Office 365
    Join Date
    Sep 2017
    Location
    UK - Wiltshire
    Posts
    3,003
    Use the date value expression:

    If rs!Deliverydate = DateValue(wTestDate)

    That strips the time value (which every date has, it's just hidden because its 0 which represents 12:00 midnight in your delivery date) from your date value.

    All Dates are stored as decimal numbers - The whole number represents the day, the decimal portion is the time. You can see this in the immeditate window:
    Code:
    Print now(),cdec(Now()) , Date(), cdec(Date())
    05/10/2023 09:13:57          45204.3846875              05/10/2023     45204
    When you store just the date the value is 45204.0000 for today. Compare that to the value with any actual time component and the comparison fails.
    DLookup Syntax and others http://access.mvps.org/access/general/gen0018.htm
    Please use the star below the post to say thanks if we have helped !
    ↓↓ It's down here ↓↓

  3. #3
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,944
    I can understand the recordset field having a time element and the local variable not, but the other way around??
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  4. #4
    TOPSie is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Mar 2021
    Posts
    108
    Many thanks

  5. #5
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,803
    Quote Originally Posted by Welshgasman View Post
    I can understand the recordset field having a time element and the local variable not, but the other way around??
    A wild guess: the date field is formatted that way so the recordset uses the format. The date variable uses the field value, not the format.
    I don't have time to test that any time soon. If you had asked me what the recordset would return I would have said the value, not the format.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

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

Similar Threads

  1. Date comparison problem.
    By bubai in forum Access
    Replies: 6
    Last Post: 09-30-2021, 02:36 AM
  2. Sum IIF date comparison issue
    By sergi117 in forum Access
    Replies: 3
    Last Post: 10-05-2018, 11:30 AM
  3. Date comparison return certain information.
    By ChrisNWV in forum Access
    Replies: 2
    Last Post: 09-22-2014, 01:09 PM
  4. RC Notation and Date Comparison
    By mkc80 in forum Access
    Replies: 2
    Last Post: 10-10-2012, 06:22 PM
  5. Short date comparison
    By andy101 in forum Programming
    Replies: 2
    Last Post: 03-17-2011, 04:36 AM

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