How do I convert a date into a string formatted per the computer's regional date setting? I only see how to specify explicit formats. For example, in PowerBuilder, I would specify date format string "[shortdate]". Forgive me if I'm missing something simple. Thanks! |
The server does not automatically format dates according to the client connection's local OS settings. Generally, that is left up to the client app which can format the date itself or have the server do it using explicit formats via dateformat arguments or the DATE_FORMAT option (https://dcx.sap.com/index.html#sqla170/en/html/813a8b556ce21014958ea27cd4f0b21c.html*loio813a8b556ce21014958ea27cd4f0b21c) |
If you really need to format dates within the server (say, because there is no client app in-place) and you are using Windows as platform, you could take the (somewhat difficult) route to use a native function calling the GetDateFormatEx() WinAPI or similar functions... Here's an article from Breck's blog with a sample using the GetOpenFileName() WinAPI - just to show the general approach. Note that this approach would give a date in the format & language of the OS where the database server is running rather than the client. Each client should follow its own rules.
(15 Sep '22, 04:32)
John Smirnios
Replies hidden
Thanks for pointing this out - I had thought the server's location would actually be meant with "the computer's regional..." - thinking of a local engine.
(15 Sep '22, 04:43)
Volker Barth
That's true. If it is a local engine on the desktop, the regional settings would match. If it is running as a service or as another user, the settings still may not match even if it is on the same machine.
(15 Sep '22, 08:22)
John Smirnios
That would depend on the used "lpLocaleName" entry within the API call, methinks.
(15 Sep '22, 08:32)
Volker Barth
Thanks, all. You bring up good points on the complexities. In this case, the server is Windows, and the client is a web application running in the Browser. The GetDateFormatEx() solution on the server will work out now, but maybe not in the future. Perhaps an application setting should define the date display format in this case? I'll give this some thought.
(15 Sep '22, 09:08)
dharrel
Replies hidden
Just to clarify: You can also set options like date_order/date_format/timestamp_format per connection and can use dateformat() with the according connection properties to provide connection-specific formatting, so possibly a client app could also provide regional settings to the server via those options...
(15 Sep '22, 09:41)
Volker Barth
|