Get dates from AUT?

0
0

My Web-based application (like most) follows the browser locale to format dates.

So if you configure British English as the preferred language in the browser, the app will display dates in “DD/MM/YYYY” format.

Now QTP (ok, it´s VBScript that is the culprit) does not know about this. It strictly follows the local machine´s locale settings.

Unfortunately, that means that if my local machine is configured to German locale, and the app is in English (because the browser is configured this way), VBScript´s DateValue function will fail (because it expects “DD.MM.YYYY” format.

So what is an elegant way to convert an AUT-displayed date value to a native VBScript date so I can do calendar calculations and checks on it?

Except for switching the current user´s locale to one that matches the browser´s language, I don´t see a solution which avoids having to write decoders/encoders for all kinds of locales myself — which looks like a huge overkill to me.

For example, a DateValue variant which lets me explicitely specify the locale to use would be great. Is there such a thing?

In general, its not just about dates, but every data item that is formatted differently depending on the locale (time specs, currency amounts, floats, …).

  • You must to post comments
0
0

Not sure about QTP, but the windows scripting host handles it via SetLocale

Option Explicit
Dim originalLocale
originalLocale
= GetLocale()
Dim aLocales
aLocales
= Array("en-us", "es-es", "de")
Dim locale, aDates, d
For Each locale in aLocales
WScript
.Echo locale
SetLocale locale
aDates
= Array( Date(), DateValue("01/02/2015"))
For Each d in aDates
WScript
.Echo FormatDateTime(d, 1)
WScript
.Echo FormatDateTime(d, 2)
Next
WScript
.Echo "-------------------------------------------------"
Next
SetLocale originalLocale
  • You must to post comments
Showing 1 result
Your Answer
Post as a guest by filling out the fields below or if you already have an account.
Name*
E-mail*
Website