如何使登录和注销之间的日期差 [英] How to make Date Difference between Login and LogOut

查看:77
本文介绍了如何使登录和注销之间的日期差的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

亲爱的朋友

在.Net Platform上以(Asp.net C#,SqlServer 2005)身份工作

我正在研究Project,因为我有一个用户登录历史记录详细信息.

我使用Gridview并将UserLoginHistory显示为

UserId,用户名,Login_Time,Logout_Time,持续时间.



现在,我需要计算用户登录和注销的登录和注销时间...并显示在工期列中.

例如...如果用户在45分钟内访问此应用程序....因此,在工期列中,它必须显示特定访问该应用程序的45分钟.


请帮帮我,

谢谢....!!

Dear Friends

Am working on .Net Platform as (Asp.net C#, SqlServer 2005)

am working on Project, in that i have a userslogin history details.

I took Gridview and displays UserLoginHistory as

UserId, Username, Login_Time, Logout_Time, Duration.



Now I need to Calculate the Login and Logout Time of Users login and Logout...and display in duration column.

such as... if the users access this application for 45 min....So, in duration column it must show 45 minutes of that particular accessed that appl.


Please help me,

Thanks u....!!

推荐答案

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


这篇关于如何使登录和注销之间的日期差的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆