Convert date from yyyy-mm-dd to dd/mm/yyyy

Version: 7.5.9.2 (X86_64) / LibreOffice Community
Build ID: cdeefe45c17511d326101eed8008ac4092f278a9
CPU threads: 4; OS: Linux 5.15; UI render: default; VCL: gtk3
Locale: pt-BR (pt_BR.UTF-8); UI: pt-BR
Calc: threaded

Happy new year everyone. I’m looking for a way to convert a date I have inside a variable with the format yyyy-mm-dd to the format my country uses which is dd/mm/yyyy. I need it to be changed in order to be displayed to the user in the form.

YYYY-MM-DD is correct. DD/MM/YYYY is not. Dates aren’t used by countries, but by users.

The correct format as specified by ISO (ISO 8601) should be understood everywhere in the world meanwhile. It is the only unambiguous way to communicate dates globally in a human-readable way. It tells “I am a date” by the way. It sorts correctly alphabetically. Why do you want to replace a good representation by a bad one? This even under the tag “base” where items actually should be data.

Unfortunately you will again find somebody telling you that “dates are numbers” and how to “convert them to a different format”. Make your own decision.

Because it is easier for the final users of the database to understand whats happening behind the values I’m showing to them.

Which type of database are you using with Base?
What is the data type of the column storing the dates?

I’m using embedded HSQLDB.

The column storing the dates is set to Data type, and its format is dd/mm/yyyy. But I have an array that gets this values, and when it does it transforms them into yyyy-mm-dd. This creates my problem of having to transform it into dd/mm/yyyy again so it can be displayed properly.

Solved!

sub ConvertData
olddata = "2004-11-28"
data = Format(DateValue(olddata), "DD/MM/YYYY")
msgbox(data)
end sub

msgbox(data) shows 28/11/2004

Unambiguous to whom? You and the people you know? Dates aren’t only used by internal systems and computers. For the general user, where I live, converting to the DD/MM/YYYY format is pretty much mandatory. Only a dev or a nerd would understand the YYYY-MM-DD format. Use the ISO for data operations and programming stuff, otherwise, present it in a human-readable way.

Do you say, that out of a thousand random people that you may encounter on streets where you live, there will be at least one who will not understand, when you show 2024-09-17? Even if that’s not the format they are accustomed to, they will 100% recognize it using common sense.

1 Like

Do you simply know or are you interested in facts and reasons?
Well, I also live in a country (Germany) where many people prefer a localised “date format”. It often is DD.MM.YY which can hardly be accepted because the century is missing. People who understand this accept and use DD.MM.YYYY. The norm for business letters (DIN) is YYYY-MM-DD, but many aren’t yet aware of it, and the standard unfortunately allows exceptions.
Nevertheless I don’t know somebody who isn’t capable of understanding YYYY-MM-DD. It may look like an arbitrary habit to prefer this or that “format”, but it isn’t. Very many people have contacts beyond their own country (private and/or business) nowadays, and specifically the “slashed” formats are ambiguous because one country supposing itself to be extremely important is fond of reverting the order of DD and MM.
I’m neither a “nerd” nor a “dev”, but somebody interested in the avoidance of misunderstandings.
In addition dates are often exchanged via networks by ordinary people who use so called csv files. Contributors in the forums I know wasted meanwhile hundreds if not thousands of hours helping people to clean-up the mess (if possible at all) they have due to the usage of ambiguous formats.
There are reasons for ordinary people who also use “office software” occasionally to use ISO 8601 with dashes.

  1. Dates are sortable in this textual representation without a conversion to numbers (again ambiguous).
  2. They are even telling “I am a date!”
  3. They are unambiguous globally.
  4. Active and passive usage are easy after a few minutes of training.

You won’t need to convert to a “nerd” to understand this.
But if you are suspecting the contributors here to be just devs/nerds, and you don’t like that kind, you should leave it at that after the few minutes you have looked at this site. It’s basically “peer-to-peer”.

3 Likes