Question
· Nov 5, 2019

Display Issue for the Date field

I have a custom written date, setup as myDate in my application, which always behaved fine for years, and now it's acting a little weird. 

When I run SQL in Display mode the date shows as 1/10/1841 for some but not ALL rows.

When I run the same exact query in logical Mode the date shows normal format, in my case, for example 10/1/2019.  When the application is running is shows the incorrect date.  When I run the terminal session and open a ref point and ask to write a date is shows 10/1/2019, but I am expecting internal format here - 65287.   

I was wondering what is causing this issue.  I am pretty much certain there are some problems with initial data setup so my question is when does the date field converts and shows as  1/10/1841 ?

as far as the code for these, it's a custom created Date and this code worked for years now... so no issues here.  The myDate field is not a required field in the class where I actually use it.

Class NAMEHERE.myDate [ ClassType = datatype, ClientDataType = DATE, OdbcType = DATE, Not ProcedureBlock, SqlCategory = DATE ]

ClassMethod LogicalToDisplay(in As NAMEHERE.uDate = "") As NAMEHERE.myString [ CodeMode = expression ]
{
$s(in="":"",1:$zd(in))
}

ClassMethod DisplayToLogical(in As NAMEHERE.myString = "") As NAMEHERE.myDate [ CodeMode = expression ]
{
$s(in="":"",1:$zdh(in))
}

there are also other methods in this class, but unrelated

Please advise,

Thank you for your time,

Discussion (4)2
Log in or sign up to continue

Hi Alex,

 "in logical Mode the date shows normal format, in my case, for example 10/1/2019"

in logical mode you get the pure content from global which is here  NOT a $H value !!

$ZD() expects an Integer to convert    =>   it is just +"10/1/2019" => 10

then $ZD(10) = " 10/1/1841"    

So it seems that some of your Dates are not stored using DisplayToLogigal resulting in an Integer
but written directly (e.g. coming from ZEN) into your object / global.

To fix it you may run something like   if +in'=in set in=$zdh(in))

if you add to your data class

Class NAMEHERE.myDate ClassType = datatype, ClientDataType = DATE, OdbcType = DATE, Not ProcedureBlockSqlCategory = DATE ]

these 2 methods you get a kind of self healing code.
It is accessed every time you load or save your property 

ClassMethod LogicalToStorage(in As NAMEHERE.myString ""As NAMEHERE.myDate CodeMode = expression ]
{
$s(+in'=in:$zdh(in),1:in)

}
ClassMethod StorageToLogical(in As NAMEHERE.myString ""As NAMEHERE.myDate CodeMode = expression ]
{
$s(+in'=in:$zdh(in)
,1:in)
}