问题
I am looking for a VBA function that would return the current OS Short date format (ex: M/d/yyyy
, dd-MMM-yy
, yy/MM/dd
, etc.) as a string. I have found such functions for MS Excel on related posts using Application.International
, but they do not work with MS Access.
I want to be able to show the OS date format in my forms to avoid confusion if '08-11-11' is displayed, for example. Using CDate()
, my dates are automatically formatted to whatever is set in Windows Date and time settings. However, users might not be aware of that.
回答1:
Just pull it from the registry.
There are many ways, the way I use:
CreateObject("WScript.Shell").RegRead("HKCU\Control Panel\International\sShortDate")
Of course, one could use WinAPI to read the registry too.
If reading the registry is really undesirable, you can always format a distinct date, for example:
Format(#2/1/3333#, "Short Date")
And then parse the result to get the format
来源:https://stackoverflow.com/questions/59460034/finding-os-short-date-format-string-in-ms-access-vba