1. Benjamin Hübner
  2. PowerBuilder
  3. Monday, 17 August 2020 12:19 PM UTC

Hello, everyone,

for years PowerBuilder has ignored the Windows setting of two-digit years.

Our customers work a lot with birth dates and want the Windows setting to be respected rather than the fixed setting listed in the PowerBuilder help. (greater or equal 50 then the 20th century - less than 50 then the 21st century)

How can this be done? We do not want to have to consider all possible date formats.

Thank you and greetings

Benjamin

Miguel Leeuwe Accepted Answer Pending Moderation
  1. Thursday, 20 August 2020 08:49 AM UTC
  2. PowerBuilder
  3. # 1

While at it ...

Here's a small sample app. (pb2017)

To see if it works you have to debug the itemchanged event.

 

Attachments (1)
Comment
There are no comments made yet.
Miguel Leeuwe Accepted Answer Pending Moderation
  1. Thursday, 20 August 2020 08:25 AM UTC
  2. PowerBuilder
  3. # 2

if you have a common dw ancestor like 'u_dw' when using pfcs:

Put this code in the ItemChanged() event. It's not perfect and might need also some checks using the max value of your windows range (which I haven't coded).

If you'd type in as a date:

24.04.37

PB would interpret that (wrongly) as 24.04.2037

Then the code lowers the date with a 100 years and keep that value if it's within the ranges of your Windows settings.

What would happen if you'd have a leap year and someone was born on 29th of February 1932?
Seems like it's not a problem (not completely sure if there are any exceptions): 2032 and 1932 are both leapyears, so the initially obtained date of 29.02.2032 is a valid date for PB for us to work our code on:

if dwo.format = "[shortdate]" then
	date ld_date
	
	ld_date = Date(DATA)
	if year(ld_date) > 1999 then
		// then you got a date in 21 century, have to check:
		// your min value = 1931 and max value = 2030
		// diminish the date with a hundred years:
		ld_date = Date(year(ld_date) - 100, month(ld_date), day(ld_date))
		// 1931 should be in some instance variable, not hard coded like I do here:
		if year(ld_date) >= 1931 then
			// this new date is the one you really wanted:
			this.SetItem(row, string(dwo.name), ld_date)
			return 2 // to reject the initial input in DATA and accept the value set with SetItem
		end if
		
		// you might also have to do some checking with the MAX value of your windows range 
		// .... to be coded ... 
		
	end if
	
end if
return 0

 

I think my initial check on format being "[shortdate]" would work for all date fields, as long as they have that format set. (but you could use some value in columns' tags to indicate the check should be done and check on that).

Hope it gives you the initial steps for your solution.

regards

 

Comment
  1. Benjamin Hübner
  2. Thursday, 20 August 2020 08:41 AM UTC
Thank you.
  1. Helpful
  1. Miguel Leeuwe
  2. Thursday, 20 August 2020 08:46 AM UTC
You're welcome.

I've added a "return 0" at the end (just for ethics, since I'm doing also a "return 2")

I've used 1931 as you minimum range value instead of 1930.

  1. Helpful
There are no comments made yet.
Benjamin Hübner Accepted Answer Pending Moderation
  1. Thursday, 20 August 2020 07:27 AM UTC
  2. PowerBuilder
  3. # 3

Thanks for your help,

but as I already wrote, it's not about the format, but about the interpretation of a two-digit year.

 

Benjamin

Comment
  1. Miguel Leeuwe
  2. Thursday, 20 August 2020 08:12 AM UTC
yes, I should have had some coffee before that answer.

I suggest doing a "feature request" on https://www.appeon.com/standardsupport/search

Then meanwhile, what you can do:

1) have the users type in 4 digits for the year (in the Edit or EditMask properties use this fixed format: "dd.mm.yyyy" and in the format itself use [shortdate], so at least the user sees the format he has configured in windows when he is not editing the field.

2) or ... you can write a generic ItemChanged script that uses the settings of windows for the century determination:

I'll past some code in a new answer
  1. Helpful
There are no comments made yet.
Miguel Leeuwe Accepted Answer Pending Moderation
  1. Thursday, 20 August 2020 07:00 AM UTC
  2. PowerBuilder
  3. # 4

EDIT: I've read you question a bit better now (sorry).

So this answer is probably no good:

----------------------------------------------

Here's the attached zipped GIF video.

Using pb2019 r2.

You have to set the format to be [shortdate] there's 2 places you have to do that.

Then you have to know how to change the format in W10, which is not as easy as it was on older windows versions anymore.

 

Another solution could be:

- read the format for date format setting from the registry:

HKEY_CURRENT_USER\Control Panel\International\sShortDate

- in the constructor event of your datawindow,run through all columns and apply that format on the date fields.

 

HTH.

Attachments (1)
Comment
There are no comments made yet.
Benjamin Hübner Accepted Answer Pending Moderation
  1. Wednesday, 19 August 2020 06:59 AM UTC
  2. PowerBuilder
  3. # 5

Sorry, but the format is not the point.

We distribute our software in Germany, Austria and Switzerland. There is no military standard and the standard format is "dd.mm.yyyy".

In the year 2020 it should be possible for RAD software for Windows programs like PowerBuilder to respect the corresponding settings of Windows.

Benjamin

Comment
There are no comments made yet.
Olan Knight Accepted Answer Pending Moderation
  1. Tuesday, 18 August 2020 23:25 PM UTC
  2. PowerBuilder
  3. # 6

Another opinion:

The format proposed by Chris is, in effect, military time:  2020-08-18.
It's very clear, and more importantly it can be sorted in that format.

I store my dates in this manner, and display them as 18-AUG-2020.

 ~~~~~~~~~~~~~~~~~~~~~~

To answer your question, ensure that you are saving the dates in a DATE format for your database.
Then in the code you cxan use the algorithm you already stated to determine the CC portion of the CCYYMMDD date, and store the full CCYYMMDD date in the database.


Olan

Comment
There are no comments made yet.
Chris Pollach @Appeon Accepted Answer Pending Moderation
  1. Monday, 17 August 2020 18:42 PM UTC
  2. PowerBuilder
  3. # 7

Hi Benjamin;

   FWIW: I always have built my PB Apps using the ANSI date standard CCYY-MM-DD and found that App users preferred this format as it's very clear. Also, all major DBMS software uses this standard internally as well (so does PB).

Just my $0.02

Regards ... Chris

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