1. Konstantin Goldobin
  2. PowerBuilder
  3. Monday, 9 October 2023 09:51 AM UTC

Hello,

I stumbled upon an old piece of code that converts the text of an Edit Mask window control to a date value using the Date() function instead of using the GetData() method. The mask is "[date]" and the MaskDataType is "datemask!".

On one particular PC configured with the "dd.MM.yyyy" date format, this code interprets the text differently depending on its value: if the first two digits can be converted to a month, it does so. If not, it converts them to a day number. For example, "14.09.2023" is correctly converted to 2023-09-14, but "12.09.2023" is converted to 2023-12-09.

I created a simple test app that does the same and the following is the result on that troublesome PC:

The "Suggested" row shows the result of using the GetData() method, however I would really like to understand what is happening here. So, I was wondering if anyone has any idea what can influence the string to date conversion apart from the date format set in Windows. I don't know if this is version specific, but I'm using PB 2019 R3 build 2728.

Thanks!

Konstantin

Accepted Answer
Konstantin Goldobin Accepted Answer Pending Moderation
  1. Thursday, 12 October 2023 07:03 AM UTC
  2. PowerBuilder
  3. # Permalink

I had to keep digging and it seems PB does not rely on sShortDate exclusively when it "attempts to match an input string to a date format". I can't be 100% sure because I don't have PB's source code, but it looks like PB uses iDate (which holds the order of date parts in sShortDate) first and only if it fails it proceeds to sShortDate. I was able to reproduce this behaviour on my PC by setting sShortDate to "dd.MM.yyyy" but iDate to 0 (month, day, year). The result was that "12.09.2023" was interpreted as 2023-12-09 while "14.09.2023" was correctly interpreted as 2023-09-14, just like shown on my screenshot. Later, it was confirmed that the PC where the problem occurred had the same settings. I'm not sure what you need to do to misconfigure date formats in Windows like that, but it happened.

Comment
There are no comments made yet.
Miguel Leeuwe Accepted Answer Pending Moderation
  1. Monday, 9 October 2023 10:28 AM UTC
  2. PowerBuilder
  3. # 1

Hi,

All I know is that powerbuilder "attempts" things when it comes to converting text to date. If what you are doing is work on for example DATA in itemchanged, that might be the case? It sounds like a bug to me anyway. See the part with yellow background below:

Syntax 2: For strings

 

Description

Converts a string whose value is a valid date to a date value.

Syntax

Date ( string )

 

Argument

Description

string

A string containing a valid date (such as January 1, 2002, or 12-31-99) that you want returned as a date. Datetime can also be an Any variable containing a string.


Return value

Date.

Returns the date in string as a date. If string contains an invalid date or an incompatible datatype, Date returns 1900-01-01. If string is null, Date returns null.

Usage

Valid dates in strings can include any combination of day (1 to 31), month (1 to 12 or the name or abbreviation of a month), and year (2 or 4 digits). PowerBuilder assumes a 4-digit number is a year. Leading zeros are optional for month and day. The month, whether a name, an abbreviation, or a number, must be in the month location specified in the system setting for a date's format. If you do not know the system setting, use the standard datatype date format yyyy-mm-dd.

PowerBuilder attempts to match the input string to a date format in the regional settings on the computer. If a complete match is not found, PowerBuilder attempts a partial match. For example, if you use Date('01-JAN-1900') and PowerBuilder finds the partial match (dd-MMM-yy), PowerBuilder parses the first two numbers of the year and gets 19. The 2-digit year is interpreted as a year between 1930 and 2029, and the date returned is 1/1/2019.

Date literals do not need to be converted with the Date function.

Comment
  1. Miguel Leeuwe
  2. Monday, 9 October 2023 10:34 AM UTC
Another thing I'm thinking of:

It seems like the problems with "VirtualStore" keys in the windows registry are back. I spent 3 hours last Friday on trying to figure out why some DB field could not be found and it turned out I was connecting to a previous version of my Database. We set our database connections in the registry. Do a search on "Virtualstore" just in case some language settings are present in one of them. You then delete that entire virtualstore branch.
  1. Helpful
There are no comments made yet.
  • Page :
  • 1


There are no replies made for this question yet.
However, you are not allowed to reply to this question.