Datatypes For Handling Date and Time in Persistent Classes

Hi, Community!

When I introduce a field to a persistent class to manage date/time what datatype should I prefer? 

%Date or %TimeStamp? And why?

  • 0
  • 93
  • 9
  • 2


%Date is just handling +$h, no time  (that would be %Time)
%Timestamp is the real object equivalent of $h

Thank you, Robert!

So, if I want to put $H to a  %Date property I do:

set s.Date=$H

do s.%Save()

for %TimeStamp property to set current date/time, I do what?

  set s.TimeStamp=$zdt($H,3)

it is already in ODBC format.


When working with $zd* functions It's better to specify what you need explicitly, because otherwise locale change can be an unwelcome surprise:


Other locales could have TimeFormat property not equal to 1, there are also custom locales.

I completely agree that in a wide range of scenarios defaults work fine, or rather defaults are what we expect them to be. However, that is not always the case, so I prefer (and advice) to use macros for $zd* functions with all relevant parameters specified.


%PosixTime is preferable to %TimeStamp, because it takes up less disk space and memory than the %TimeStamp data type and provides better performance than %TimeStamp.proof

in technology space it's nice and compatible to the UNIX/LINUX world
in the commercial arena it is just an alien

This datatype is not present in (currently latest) Caché 2017.2; it appears to be IRIS-only. That rather limits its usefullness. Besides, what is the performance of a datatype, and where is that a bottleneck?

Time in Posix is the time as %Integer counting from Jan 1st, 1970.  A UNIX definition.
dates before are negative integers (e.g. birthdate before 1970 wink )   
      [that was a reason to start $h with Jan 1st, 1840. The year the oldest veteran (in 1960)  from civil war at MGH was born ]