Get startup time of session

Posted by Lieven De Foor on 27-Oct-2015 11:43

Hi,

Is there any way to get the startup time of a session?

Posted by Brian K. Maher on 27-Oct-2015 11:46

Hi Lieven,
 
If your code does not reset the ETIME function, you can subtract the value of ETIME from the current time to get the session start time.
 
Brian
 

Posted by olivier.dunemann on 28-Oct-2015 01:33

Assuming you are under MS Windows:

MESSAGE System.Diagnostics.Process:GetCurrentProcess():StartTime

       VIEW-AS ALERT-BOX INFO BUTTONS OK.

All Replies

Posted by Brian K. Maher on 27-Oct-2015 11:46

Hi Lieven,
 
If your code does not reset the ETIME function, you can subtract the value of ETIME from the current time to get the session start time.
 
Brian
 

Posted by James Palmer on 27-Oct-2015 11:48

Yes. It's in the _Connect table, column _Connect-time.

_MyConnection is a link to the _Connect of the current session if that's of any use.

Posted by Brian K. Maher on 27-Oct-2015 11:54

James,
 
Does that value define the start of the client session or the time when the client connected to a given database?
 
Brian

Posted by Brian K. Maher on 27-Oct-2015 11:54

Here is some simple code that does it:
 
DEFINE VARIABLE VStartTime AS DATETIME NO-UNDO.
 
VStartTime = ADD-INTERVAL(NOW, (ETIME * -1), "milliseconds").
 
DISPLAY VStartTime.

Posted by James Palmer on 27-Oct-2015 12:02

You're right it's connect time to the database, so has to be taken with a pinch of salt.

Posted by Brian K. Maher on 27-Oct-2015 12:08

James,
 
ETIME has the same issue.  It works well assuming it was never reset.  <smile>
 
Lieven .. what you want would actually make a good enhancement request.  Perhaps an attribute that hangs off of the SESSION handle.  I think you should submit it to the Ideas section.
 
Brian

Posted by olivier.dunemann on 28-Oct-2015 01:33

Assuming you are under MS Windows:

MESSAGE System.Diagnostics.Process:GetCurrentProcess():StartTime

       VIEW-AS ALERT-BOX INFO BUTTONS OK.

Posted by Lieven De Foor on 28-Oct-2015 03:37

Thanks for the suggestions guys.

I think I can use the ETIME solution, although I can never be 100% sure no one has reset it before (by convention here, we should never reset it, so it should be safe).

I need a solution that works both on Unix and Windows (AppServer), so I might get away with the Olivier's suggestion using conditional compilation on Windows.

I could also store the NOW value in a globally available property at session startup, but I would rather use some built-in attribute. Something like SESSION:START-TIME would have been great indeed Brian.

I'll log it as (yet another) Idea.

Posted by Patrick Tingen on 11-Nov-2015 14:09

You probably want to have the SESSION:STARTUP as a datetime type, right?

Posted by Brian K. Maher on 11-Nov-2015 14:15

Patrick, I would go all the way and make it a DATETIME-TZ data type (just cause we can & you just know someone down the road will care about the timezone <smile>).

Posted by Patrick Tingen on 17-Nov-2015 05:06

Yes, of course! I hardly ever use TZ fields but you are absolutely correct; TZ it should be!

This thread is closed