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!

asked 14 Sep, 11:36

dharrel's gravatar image

dharrel
1458815
accept rate: 0%


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)

permanent link

answered 14 Sep, 12:05

John%20Smirnios's gravatar image

John Smirnios
11.2k394151
accept rate: 38%

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.

permanent link

answered 15 Sep, 04:21

Volker%20Barth's gravatar image

Volker Barth
38.9k351532800
accept rate: 34%

edited 15 Sep, 04:23

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, 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, 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, 08:22) John Smirnios

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

(15 Sep, 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, 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, 09:41) Volker Barth
showing 2 of 6 show all flat view
Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Question tags:

×10
×7

question asked: 14 Sep, 11:36

question was seen: 91 times

last updated: 15 Sep, 09:41