且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何使登录和注销之间的日期差

更新时间:2023-01-20 09:41:18

在C#中很简单:
In C# it''s easy:
TimeSpan diff = logoutTime - loginTime;
Console.WriteLine(diff.TotalMinutes);


要以SQL返回它:


To return it in SQL:

SELECT DATEDIFF(mi, Logout_time, LoginTime) as Mins FROM UserLoginHistory


请尝试以下操作来计算持续时间.

Try below for calculating the duration.

SELECT DATEDIFF(hour, '2005-12-31 23:59:59.9999999'

, '2006-01-01 00:00:00.0000000');

SELECT DATEDIFF(minute, '2005-12-31 23:59:59.9999999'

, '2006-01-01 00:00:00.0000000');

SELECT DATEDIFF(second, '2005-12-31 23:59:59.9999999'

, '2006-01-01 00:00:00.0000000');



有关更多信息,请使用下面的链接

http://msdn.microsoft.com/en-us/library/ms189794.aspx [ ^ ]



For more information use below link

http://msdn.microsoft.com/en-us/library/ms189794.aspx[^]


我认为您可以分别在用户登录和注销时节省登录和注销时间.
如果您有这两个时间,则只需将这两个时间之间的差计算为持续时间即可.

否则,只需详细说明问题即可.
保存这些登录和注销时间时是否遇到问题?
I think you can save the log-in and log-out time when user log-ins and log-outs respectively.
If you have these two time, then you can just calculate the difference between these times as the Duration.

Or else just explain in details about the problem.
Are you facing problem when saving these log-in and log-out time ?