Page 1 of 1

Virtual Field

Posted: Fri Aug 07, 2020 8:06 am
by Fromm603
Trying to create my first virtual field. Our IBMi database stores the date in 4, 2 character fields (each 2,0). I want to create a virtual field that is MMDDYY (don't need century). My virtual field derivation looks like the below, is there a better way?

#SOendymd := (#soendy.AsString + #soendm.AsString + #soendd.AsString).AsNumber

Somehow this doesn't seem to work all of the time.

Re: Virtual Field

Posted: Sat Aug 08, 2020 7:38 am
by caseywhite
I suspect the issue is that single digit numbers are being set to a 1 character string instead of 2 character string left padded with 0's. If you change your code to the following it will probably resolve your issue.

#SOendymd := (#soendy.AsString.RightAdjust(2 '0') + #soendm.AsString.RightAdjust(2 '0') + #soendd.AsString.RightAdjust(2 '0')).AsNumber