Question
Evgeny Shvarov · Apr 13, 2018

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
1 696
Discussion (12)2
Log in or sign up to continue

%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?

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?

Hi Robert,

Why did you say that the %TimeStamp datatype is the equivalent of the full $h? It's true that %Date/%Time do the conversion from internal date/time values to/from external. But %TimeStamp, %DateTime, and %StringTimeStamp  do not do any internal/external conversion. It's just for the YYYY-MM-DD HH:MM:SS external timestamp. Is there something I'm missing?

%PosixTimeStamp does convert, but it's not $h internally.

%PosixTime

%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

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

it is already in ODBC format.

$zdt($H,3)

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

$zdt($H,3,1,0)

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.

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 ]