简体   繁体   中英

Finding OS short date format string in MS-Access/VBA

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM