cancel
Showing results for 
Search instead for 
Did you mean: 

dateformat (...) to regional date format

dhkom
Participant
841

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!

View Entire Topic
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...