Written by

Lead Technical Analyst at Missouri Health Connection
Question Scott Beeson · Oct 18, 2016

Total Timestamp Confusion, please help.

This tells me that there is no timezone offset on this table/field:

Select TOP 1 GETDATE() as Now, TimeCreated FROM ens.messageheader ORDER BY TimeCreated DESC;
Now                 TimeCreated         
------------------- ------------------- 
2016-10-18 16:16:49 2016-10-18 16:16:31 

 

So why is TimeCreated in this resultset 4 hours less than OneMinuteAgo when I'm clearly requesting only records with a TimeCreated greater than OneMinuteAgo?

Select TOP 1 DATEADD(mi, -1, GETDATE()) as OneMinuteAgo, TimeCreated FROM ens.messageheader WHERE TimeCreated > DATEADD(mi, -1, GETDATE()) ORDER BY TimeCreated ASC;
OneMinuteAgo        TimeCreated         
------------------- ------------------- 
2016-10-18 16:17:51 2016-10-18 11:17:56 

Comments

Scott Beeson  Oct 19, 2016 to Eduard Lebedyuk

I'm not exactly sure what you're asking, but this is the definition in the ens.messageheaderbase class:

Property TimeCreated As Ens.DataType.UTC

0
Tirthankar Bachhar · Oct 19, 2016

Can you change from display mode to logical mode. You should get the correct one. 

0
Tirthankar Bachhar  Oct 19, 2016 to Scott Beeson

Try running the same from system management portal, if you have access. I'll try to find the similar option for DBVis.

0
Tirthankar Bachhar  Oct 19, 2016 to Tirthankar Bachhar

Another text from DocBook, that will help you.
GETDATE returns the current local date and time as a TIMESTAMP. All Caché SQL timestamp, date, and time functions except GETUTCDATE are specific to the local time zone setting. GETUTCDATE returns the current UTC (universal) date and time as a TIMESTAMP. You can also use the Caché ObjectScript $ZTIMESTAMP special variable to get a current timestamp that is universal (independent of time zone).

0
Tirthankar Bachhar  Oct 19, 2016 to Tirthankar Bachhar

Run below query from DBVis. You may use GETUTCDATE rather than GETDATE.

Select DATEADD(mi, -1, GETDATE()) As CurrentDateLess1Min, GETDATE() As CurrentDate, DATEADD(mi, -1, GETUTCDATE()) As CurrentUTCDateLess1Min, GETUTCDATE() As CurrentUTCDate

0
Scott Beeson  Oct 19, 2016 to Tirthankar Bachhar

CurrentDateLess1Min    2016-10-19 10:50:43 
CurrentDate            2016-10-19 10:51:43 
CurrentUTCDateLess1Min 2016-10-19 15:50:43 
CurrentUTCDate         2016-10-19 15:51:43 

 
0
Tirthankar Bachhar  Oct 20, 2016 to Scott Beeson

Do you still have confusion? Does this solve your issue? If yes please let me know.

0
Scott Beeson  Oct 20, 2016 to Tirthankar Bachhar

Changing my queries to GETUTCDATE() did seem to fix the issue but I still don't understand why.   ¯\_(ツ)_/¯

0
Scott Beeson  Oct 20, 2016 to Scott Beeson

Added a new top level comment since this thread is getting tight.  I'd love to see your thoughts.

0
Scott Beeson  Oct 20, 2016 to Tirthankar Bachhar

This might better explain what I'm seeing or not understanding:

SELECT DATEADD(hh, -1, GETDATE()) as OnlyAfterThisDate, MIN(TimeCreated) as FirstDate, MAX(TimeCreated) as LastDate FROM ens.messageheader WHERE TimeCreated > DATEADD(hh, -1, GETDATE());

SELECT DATEADD(hh, -1, GETUTCDATE()) as OnlyAfterThisDate, MIN(TimeCreated) as FirstDate, MAX(TimeCreated) as LastDate FROM ens.messageheader WHERE TimeCreated > DATEADD(hh, -1, GETUTCDATE());

0
Scott Beeson  Oct 20, 2016 to Scott Beeson

Wait, I think I understand now.  In the second query, >8:01 is what I actually want since it was currently 9:01.  FirstDate is stored in UTC but my client is automatically adjusting, so it works when I compare it to UTC.  The local value for "OnlyAfterThisDate" isn't adjusted when displayed.

I'm not sure I'm verbalizing it correctly, but I think I do understand now.

0