22
Views
8
Comments
Solved
Calculate total number of hours

How to get calculat total number of hours using two variable (login date time and logout date time ) the first variable sort in an entity when user login and the  variable sort in the same entity when user logout date time

Rank: #70
Solution

Hi Andrew,


You want to know the duration in hours of the user between the time he logs in and logs out, is that it?

To calculate the number of hours between two date times, you can use the OutSystems built-in function DiffHours, example below:


Regarding the login date time and logout date time, the first one is saved and handled automatically on the platform, on the attribute Last_Login from the table User (from System):


Nonetheless, the logout date time is not saved by default, so you would have to have to create a table to store this information. You could create for instance a table User_Extended with the UserId and LastLogoutDate to be filled when the user presses logout. After having the logout and login, you can easily get the hours difference using the DiffHours function mentioned above.


Hope it helps.


Regards,
João

Rank: #1593
Solution

hi Andrew,

The Last_login attribute which you will fetch from User entity assign it to DateTime1. The LastLogoutDate attribute which you will fetch from User_Extended entity  assign it to DateTime2. Then use it DiffHours(DateTime1,DateTime2)


Rank: #70
Solution

Hi Andrew,


You want to know the duration in hours of the user between the time he logs in and logs out, is that it?

To calculate the number of hours between two date times, you can use the OutSystems built-in function DiffHours, example below:


Regarding the login date time and logout date time, the first one is saved and handled automatically on the platform, on the attribute Last_Login from the table User (from System):


Nonetheless, the logout date time is not saved by default, so you would have to have to create a table to store this information. You could create for instance a table User_Extended with the UserId and LastLogoutDate to be filled when the user presses logout. After having the logout and login, you can easily get the hours difference using the DiffHours function mentioned above.


Hope it helps.


Regards,
João

Rank: #1593
Solution

hi Andrew,

The Last_login attribute which you will fetch from User entity assign it to DateTime1. The LastLogoutDate attribute which you will fetch from User_Extended entity  assign it to DateTime2. Then use it DiffHours(DateTime1,DateTime2)


The propose solution works... but needs that the user make logout for register the hours.

What can we do for the situation that the session finish without user intervention ?


Best regards