1. Glenn Barber
  2. PowerBuilder
  3. Saturday, 29 December 2018 01:56 AM UTC

In PB 2017 R3 1858  the Date ("string") function doesnt seem to recognise 4 digit years

In my case I have to conver strings like 31-Dec-2012  But  Date("31-Dec-2012") returns 12/31/2020 (in US M/d/yyyy)

From what I can tell the Date function is only looking at the first 2 digits of the year.

Is this a bug?

In the documentation 

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

 

 

Chris Pollach @Appeon Accepted Answer Pending Moderation
  1. Monday, 31 December 2018 04:51 AM UTC
  2. PowerBuilder
  3. # 1

Hi Glenn;

   Actually, the Date( ) method is working as per is documentation in the PB Help file ..

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.

     The key is also the current regional settings. Personally, I never use anything but the ANSI ISO date standard which is CCYY-MM-DD as input to the Date() method. I then rely on the use of Display Masks to show the date externally. On date input, I always force the user to give the Apps the ANSI ISO format by using Edit Masks "CCYY-MM-DD"  so that there is no date ambiguity.


HTH

Regards ... Chris

 

Comment
There are no comments made yet.
Olan Knight Accepted Answer Pending Moderation
  1. Sunday, 30 December 2018 19:42 PM UTC
  2. PowerBuilder
  3. # 2

Yes. Which is why I suggested he try using the "/" date field separators.

Olan

Comment
There are no comments made yet.
Glenn Barber Accepted Answer Pending Moderation
  1. Saturday, 29 December 2018 20:45 PM UTC
  2. PowerBuilder
  3. # 3

My Setting are identical... yet the Date Function does not produce the correct result.

Comment
There are no comments made yet.
Olan Knight Accepted Answer Pending Moderation
  1. Saturday, 29 December 2018 16:21 PM UTC
  2. PowerBuilder
  3. # 4

First check your REGION & DATE settings to see what your platform is using as the DATE format

Control Panel --> Region & Date

 

If the format is not what you want, then change it.

 

The call to  Date ("12/31/2012") should return the correct date of 31-DEC-2012.


Olan

 

Comment
  1. Glenn Barber
  2. Sunday, 30 December 2018 00:20 AM UTC
As earlier - my settings are the same as yours on Win 10 and Date doesnt work.!
  1. Helpful
  1. Brad Mettee
  2. Sunday, 30 December 2018 14:34 PM UTC
Olan - The call he's making is Date("31-Dec-2012"), not Date("12/31/2012").

I can confirm there's a problem.

PB 2017 build 1681

Date("31-Dec-2012") returns 12/31/2020

Date("31-Dec-12") returns 12/31/2012

  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.
We use cookies which are necessary for the proper functioning of our websites. We also use cookies to analyze our traffic, improve your experience and provide social media features. If you continue to use this site, you consent to our use of cookies.