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

    Date/Time handling

    I know this is one of the most confusing things in Access/vba, but can anyone explain this particular nuance



    I have a Table with a field called PaymentDate defined as Date/Time.

    In code I have a variable Dim wDate as Date.

    I get wDate from the screen - wDate = Me.txtDate

    So as I am in England I am using the dd/mm/yyyy format

    Now I store it in the table
    DoCmd.RunSQL "UPDATE Table SET Table.PaymentDate =#" & wDate & "#

    If you now look at the table (looking at the entries made in December, you see that if the day number is > 12 then the date appears correctly (English form) but if the day is 12 or less the date gets converted to American

    So 29/12/2022 appears in the table as 29/12/2022
    but 6/12/2022 is rendered as 12/06/2022

    So confusing

  2. #2
    Micron is offline Very Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    13,425
    Perhaps this will help you understand what's going on
    http://allenbrowne.com/ser-36.html
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  3. #3
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    6,570
    Use USA format mm/dd/yyyy or yyyy-mm-dd every time.

    I used this in some of my DBs after finding it on the net

    Public Const strcJetDate = "\#mm\/dd\/yyyy\#" 'Needed for dates in queries as Access expects USA format.
    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
    Minty is offline VIP
    Windows 10 Office 365
    Join Date
    Sep 2017
    Location
    UK - Wiltshire
    Posts
    3,158
    I amended the Allen Browne code to use yyyy-mm-dd , it removes any ambiguity when you are debugging, and the same format (albeit with a different escape character) works in SQL Server.
    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 ↓↓

  5. #5
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    6,570
    Quote Originally Posted by TOPSie View Post
    I know this is one of the most confusing things in Access/vba, but can anyone explain this particular nuance

    I have a Table with a field called PaymentDate defined as Date/Time.

    In code I have a variable Dim wDate as Date.

    I get wDate from the screen - wDate = Me.txtDate

    So as I am in England I am using the dd/mm/yyyy format

    Now I store it in the table
    DoCmd.RunSQL "UPDATE Table SET Table.PaymentDate =#" & wDate & "#

    If you now look at the table (looking at the entries made in December, you see that if the day number is > 12 then the date appears correctly (English form) but if the day is 12 or less the date gets converted to American

    So 29/12/2022 appears in the table as 29/12/2022
    but 6/12/2022 is rendered as 12/06/2022

    So confusing
    Not really. The first is unambiguous, there are not 29 months, so has to be ddmmyyyy.
    Second is ambiguous, is it dd/mm or mm/dd????
    As Access expects/demands mmddyyyy ( MS is a USA company after all ) that is what it chooses to go for.

    Up to you to say? and say which correctly.

    Once you understand that, it is easy.
    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

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

Similar Threads

  1. Replies: 5
    Last Post: 10-05-2022, 02:48 PM
  2. Error Handling in Run time
    By Homegrownandy in forum Programming
    Replies: 26
    Last Post: 02-25-2019, 05:13 AM
  3. Replies: 7
    Last Post: 12-18-2015, 11:43 AM
  4. Replies: 11
    Last Post: 07-20-2014, 06:22 PM
  5. Handling Inventory Costs That Change Over Time
    By mubtuhogar in forum Database Design
    Replies: 5
    Last Post: 10-12-2010, 09:19 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