cancel
Showing results for 
Search instead for 
Did you mean: 

dateformat (...) to regional date format

dhkom
Participant
843

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!

Accepted Solutions (0)

Answers (2)

Answers (2)

johnsmirnios
Employee
Employee

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*loio813a8b556ce...

VolkerBarth
Contributor

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.

johnsmirnios
Employee
Employee
0 Kudos

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.

VolkerBarth
Contributor
0 Kudos

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.

johnsmirnios
Employee
Employee
0 Kudos

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.

VolkerBarth
Contributor
0 Kudos

That would depend on the used "lpLocaleName" entry within the API call, methinks.

dhkom
Participant
0 Kudos

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.

VolkerBarth
Contributor
0 Kudos

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...