A Date With PowerBuilder
Y2K and other date related issues which affect PowerBuilder applications |
Last Updated 02 June 1998 |
Y2K compliance has become a raging issue in the developer and the user community. I have discussed this issue with a lot of PowerBuilder developers and the response has varied from inordinate paranoia to off-guard complacency. While I agree that there is probably no need for PB developers to panic, it is true that a lot of PowerBuilder applications developed in recent times and the ones currently being developed are susceptible to the Y2K problem. The problem is aggravated by the disparate manner in which dates are used in a PowerBuilder application. This article aims to explorer some of the areas in a typical PowerBuilder application where the Y2K anomaly can creep in.
The information presented here is based on my experience in developing applications with PowerBuilder and Sybase SQL Server and the following technical documents available at the Sybase tech support site-
I strongly recommend that you read the white paper (Doc ID 20030) even if
you are not using Sybase as your database.
Note Sybase has certified only PowerBuilder 5.0.04 and above to be Y2K compliant! You can check out this link - http://www.sybase.com/inc/corpinfo/year2000_matrix.html So what's wrong with 5.0.03? Click here |
I really don't want to get into the nitty-gritty details of defining the Y2K problem itself. There is already a lot of technical literature devoted to that. You may check out the Sybase white paper for a comprehensive definition of Y2K compliance and Y2K compliance standards. To put it in a nutshell, we want our applications to -
date d1 = Date("9999-12-31") You can verify this via the debugger too. Weird, huh? |
The PowerSoft document claims that PowerBuilder
can handle years from 1000 to 3000. I tried to verify this using PB5.0.0.0 and I
must say that some of the results were quite unexpected and surprising. What I came up with is shown in this table. As can be seen, the date range support is extremely inconsistent and confusing. Of course, a lot of these extremes may not be relevant to your PowerBuilder applications, but it is important to know the limitations, lest you make an incorrect assumption while developing applications. Also note the following facts-
|
It is often perceived that the Y2K problem is limited to incorrect storage of dates - like the old COBOL programs which only stored the last two digits of the year part to save space. While the incorrect storage problem has been greatly alleviated by modern day DBMS, it is infact the PowerBuilder user interface which is most susceptible to the millennium bug due incorrect interpretation of the user input. Here are some potential pitfalls-
Typical PowerBuilder applications make use of the EditMask window control or the EditMask datawindow column edit style to input dates. Problems might arise if the EditMask specifies only 2 digits in the year part. For example - 'dd/mm/yy' or 'mm/dd/yy'. This leaves the interpretation of the year to PowerBuilder which interprets it as follows-
I have seen a few applications, where in the zealousness to follow the Windows GUI standards the GUI designers went to the extent of specifying the date EditMasks as '[date] International'. The idea is that the EditMask should appear as per the Windows Short Date Format settings on the user's machine. If you have noticed, Microsoft applications like Schedule+ and Outlook sport this kind of a behavior.
I am a huge fan of the Windows GUI and I usually put in a lot of effort to ensure that my applications have the Windows 'look and feel'. But this is where I draw the line. Integrity of enterprise data is of paramount importance. Jeopardizing this integrity for the sake of relatively frivolous features like 'look and feel' is foolish.
It's hard to believe that there are applications which don't use EditMasks at all to
input dates. I saw one jut last month. In such a situation, PowerBuilder expects the dates
to be in the Windows short date format.
The PowerBuilder function Date(String) is used to convert a string to date. The
IsDate() function checks if a string contains a valid date. As you can see there is
no way one can specify the format in which the date is to be interpreted. Something like
Oracle's ToDate function in which one can indicate the date format would have been useful.
So how does PowerBuilder figure out the date format? It doesn't. Here is how it works -
The lack of awareness of the effect of the Windows Short-Date format can have severe repercussions. I know of a team which faced a lot of problems while developing an application with PowerBuilder 4.0. During the early stages of development the developers had trouble converting strings to dates. After some shallow investigating they arrived at the conclusion that PowerBuilder expects the date format to be 'mm/dd/yyyy' to correctly convert a string to a date. Unaware that this just happened to be the Windows Short-Date format on the developer's machine, they went ahead with developing the application under the assumption that PowerBuilder expects the date format to be 'mm/dd/yyyy'. The project was a huge one and it was only one and half years later that they realized the connection between the Windows Short-Date format and PowerBuilder's interpretation of dates. Too late to change the mammoth amount of code already written with the incorrect assumption, the developers tried a lot of ways to force the short date format on the user's machine to 'mm/dd/yyyy'. Finally, the only reliable solution they could come up with was to specify in the User's Manual that the Windows Short-Date format has to be set to 'mm/dd/yyyy'. Needless to say, this caused a lot friction with the user community.
As you may have realized out by now, PowerBuilder intemperately depends upon the Window Short-Date format to interpret dates. The risk of misinterpretation of dates can be greatly reduced by eliminating this dependency. Taking care that the Year part of a date always specifies all the four digits will ensure that the Y2K bugs do not creep in to the application. Here are a few guidelines-
Str_Date = "12-25-1925"
Int_Year = Integer(Right(Str_Date,4))
Int_Mon = Integer(Left(Str_Date,2))
Int_Day = Integer(Mid(Str_Date, 4,2))
dt_myDate =Date(Int_Year, Int_Mon, Int_Day)
Ideally you should put this in a global function or make it a part of a date service like PFC's n_cst_datetime.
As I said earlier, most popular DBMS do not have a problem with storing dates greater than 2000. However problems might occur while manipulating data. Even though the DBMS can handle dates beyond 2000 nothing can prevent a disaster if you specify only two digits in the year part or use an ambiguous date format in which the DBMS cannot clearly figure out the Month and the Day parts.
When using Embedded SQL and Dynamic SQL, if you specify the date in an ambiguous format then interpretation of the date is left to the DBMS and you run the risk of the date being misinterpreted. Again, a two digit year date format will cause a lot of problems with interpretation. How the DBMS interprets a 2 digit year may vary from DBMS to DBMS and you should check your DBMS' policy on this issue. Also, you should check if the DBMS expects the date to be in a particular format. For example in case of Oracle, the date must be specified as per the date format specified in the NLS_DATE_FORMAT parameter (else you must use the ToDate() function).
For example instead of using specifying the date in the following manner-
Insert Into MyTable
Values(1, "Jiggy", '1996-01-01') ;
Use a PowerBuilder Date variable-
Date dt = 1996-01-01
Insert Into MyTable
Values(1, "Jiggy", :dt) ;
How you use dates in processing will largely depend on the application you are developing. However here are some typical examples of processes that involve dates -
If you have ensured correct date interpretation and correct date storage then you have little to worry about in this area. But bugs might creep due to subtle mistakes in programming. Here are some guidelines-
Jiggy, 22nd March 1998
Back to my HomePage