Ask Your Question

reading the date acceptance pattern & locale setting [closed]

asked 2016-01-20 20:08:00 +0100

jay Arr gravatar image

updated 2020-07-12 20:35:10 +0100

Alex Kemp gravatar image

I've just publicly released an LibreOffice multi-platform, OS independent LibreOffice BASE/Writer application. I developed it using LO Version: and OSX 10.10.5. With the exception of OSX 10.11(theres an outstanding bug report) it runs on all Windows, OSX & Linux/Ubuntu systems very well.

However it fell over when my first US user tried to run it because my development platform defaults to a Locale setting of English (UK) and a Date acceptance pattern of D/M/Y;D/M;D-M. The application failed when it was attempting to coerce a a string field that was "19/01/2016" using the Cdate function to a date. I'm assuming that his system defaulted to the US Date acceptance pattern of M/D/Y;M/D;M-D and that's why it failed.

My questions is

How can I retrieve (using a macro) the local date acceptance pattern & locale setting? So that I might be able to prevent this happening.

And does anyone have any advice for handling dates information e.g. date last modified dates of files, sorting records asc. & desc. by date, best format to hold date information in a database so that I can cope with any local date format preference.

Second question:

Can I, via a macro, re-set the date acceptance pattern to the ISO standard date format YYYY/MM/DD and do you think this would be acceptable (it would certainly be a lot less confusing) ?

edit retag flag offensive reopen merge delete

Closed for the following reason question is not relevant or outdated by Alex Kemp
close date 2020-08-29 11:51:30.398296

2 Answers

Sort by » oldest newest most voted

answered 2016-01-26 00:03:16 +0100

jay Arr gravatar image

I realised I don't need to retrieve the locale date setting; there's an easier (if not very elegant) way. I've found a simple answer to the problem with this (what I've termed) tripwire code:

dim testDate    as date

On a UK system this statement will work because the default date format is D/M/Y On a US system this statement will fail because the default date format is M/D/Y

I have discovered that the 'problem' with dates ONLY appears when you attempt to coerce a date with cDate or you input a date in an unacceptable format. Internally dates are held as a decimal number and when displayed, unless reformatted, will default to whatever the default format is.

BTW: I rejected a universal solution which would be to insist that all users adopt the ISO standard. I don't think this is a realistic approach. My attitude to systems design is that the system should adapt to the user and not the other way around.

edit flag offensive delete link more

answered 2016-01-21 05:03:12 +0100

oweng gravatar image

updated 2016-01-22 04:34:43 +0100

This is a partial answer. What is appropriate is something you will need to determine for yourself and your customers. In XLocaleData4 there is a public member function to get date acceptance patterns. API page here. Perhaps this is what you are looking for? If not, I would advise asking the developers.

edit flag offensive delete link more


Thank you I don't know how to access/code the macro to access XLOCALDATA4 to get the date acceptance patterns. Can anyone help please?

jay Arr gravatar imagejay Arr ( 2016-01-21 17:08:28 +0100 )edit

Question Tools

1 follower


Asked: 2016-01-20 20:08:00 +0100

Seen: 824 times

Last updated: Jan 26 '16