Results 1 to 12 of 12
  1. #1
    Raddle is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    Sep 2021
    Posts
    60

    UK vs US Date format when opening a form

    Hi

    Could anyone give me a steer on how to tackle this little gem .. So my link-to-Excel-table of data, has UK date format, so the 4th August looks like this 04/08/2023.

    My form provides a list of logins grouped by date and the data field on the form has this click event procedure:



    DoCmd.OpenForm "frm_MainList", acFormDS, , "[Date] = #" & Me.Date & "#"

    However when activated, say for 04/08/2023's logins, the db displays the list for 8th April!

    Nice and no, I didn't spot it for while

    Any hints on how to handle this?

    Thank you so much

  2. #2
    Bob Fitz's Avatar
    Bob Fitz is offline Access Developer
    Windows 10 Access 2019
    Join Date
    May 2011
    Location
    Essex UK
    Posts
    3,544
    Allen Browne has some words of wisdom on dates: http://allenbrowne.com/ser-36.html
    If this helped, please click the star at the bottom left of this posting and add to my reputation . Many thanks.
    Bob Fitzpatrick

  3. #3
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,940
    I used this in some of my DBs' Your format in Excel would be dd/mm/yyyy, but like Access the date is actually stored as a number.

    Code:
    Public Const strcJetDate = "\#mm\/dd\/yyyy\#"  'Needed for dates in queries as Access expects USA format.
    Just format your date value with strCJetDate
    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
    Raddle is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    Sep 2021
    Posts
    60
    Thanks both .. where do I need to put the Public const line ?

  5. #5
    CJ_London is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,430
    Personally I format using the the sql standard of "yyyy-mm-dd"

    "[Date] = #" & format(Me.Date,"yyyy-mm-dd") & "#"

    Note that Date is a reserved word (the function Date()) and should not be used as a field or control name. It can generate misleading error messages. Use a meaningful name such 'orderDate', 'searchDate', entryDate'

  6. #6
    Raddle is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    Sep 2021
    Posts
    60
    Wow! Fab fab fab. Thank you so much. That nailed it although I am not sure why. Shouldn't it be dd-mm-yyyy?

    But right now .. I don't care that much.

    Thanks again

  7. #7
    Raddle is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    Sep 2021
    Posts
    60
    Not sure how to mark this one as solved ... or does the admin do that?

  8. #8
    Minty is offline VIP
    Windows 10 Office 365
    Join Date
    Sep 2017
    Location
    UK - Wiltshire
    Posts
    3,003
    yyyy-mm-dd is unambiguous, no matter what local or your regional settings say. When you are debugging strings you don't have to think which format it might be in.
    Therefore if you have to do anything with dates, it's the best way to handle it. It is also the format SQL Server recognises, so is easier to just go with it in case you ever change the source database.
    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 ↓↓

  9. #9
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,940
    Quote Originally Posted by Raddle View Post
    Not sure how to mark this one as solved ... or does the admin do that?
    Top right of the thread, might be marked Thread Tools?
    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

  10. #10
    CJ_London is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,430
    That nailed it although I am not sure why. Shouldn't it be dd-mm-yyyy?
    Dates are stored as numbers, for example today is
    ?cdbl(date())
    45146
    ?cdbl(now())
    45146.5799421296

    the date is the bit before the decimal point and is the number of days since 31/12/1899 (so 1 is the 1st Jan 1900)
    the bit after the decimal point is the number of seconds so far today divided by the number of seconds in a day (86400) - so 6am for example would be 0.25

    what you see as dd/mm/yyyy is just a format of that number specified by your window settings.

    SQL on the other hand will interpret a string on the basis of it's own standard of yyyy-mm-dd or the US format of mm/dd/yyyy

    You are passing a string with your "[Date] = #" & Me.Date & "#" criteria

    However sql is clever enough to know there are only 12 months in the year, so if you pass a value of say '31/07/2023' it will interpret that as dd/mm/yyyy. Which is probably what happened in your case - you started developing on or after 13th July and until you reached 1st August you would not realise you had a problem.

  11. #11
    Raddle is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    Sep 2021
    Posts
    60
    Thank you all so much. Great day for learning 'stuff'

  12. #12
    Bob Fitz's Avatar
    Bob Fitz is offline Access Developer
    Windows 10 Access 2019
    Join Date
    May 2011
    Location
    Essex UK
    Posts
    3,544
    Quote Originally Posted by Raddle View Post
    Thank you all so much. Great day for learning 'stuff'
    Every day's a "School day"
    If this helped, please click the star at the bottom left of this posting and add to my reputation . Many thanks.
    Bob Fitzpatrick

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

Similar Threads

  1. Replies: 2
    Last Post: 12-05-2019, 04:18 PM
  2. Replies: 3
    Last Post: 12-30-2016, 10:27 AM
  3. Replies: 4
    Last Post: 03-12-2013, 06:49 PM
  4. Replies: 8
    Last Post: 06-04-2012, 07:20 AM
  5. Date format on Form
    By onenessboy in forum Forms
    Replies: 4
    Last Post: 12-07-2010, 06:28 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