时间间隔显示为负 [英] time interval showwing negative
问题描述
亲爱的所有
Iam在一个人力资源项目中,我需要为员工定义Shift
Shift的打孔卡有两个区域,Swipein和swipeOut.我使用两个datetimepicker格式为时间,将showupdown设置为true来设置刷卡进出时间
像这样阅读
Dear all
Iam in a HR project and I need to define Shift for Employees
Shift had two feilds for punchcards reading , Swipein and swipeOut . I use two datetimepicker with format as time and showupdown as true to set the swipe in and out time
and read like this
public void calculateduration()
{
TimeSpan swipein = dtp_toTime.Value.TimeOfDay;
TimeSpan swipeout = dtp_FromTime.Value.TimeOfDay;
TimeSpan duration = dtp_toTime.Value.TimeOfDay - dtp_FromTime.Value.TimeOfDay;
MessageBox.Show(duration.ToString());
}
在我的SQL Server数据库中,我将所有这三个字段swipein,swipeout,duration都设置为Time数据类型,并且我想在其中插入这些值
为了测试,我给出了四个值
Swipein Swipeout持续时间(显示输出)
>>>>>>>>>>"
3 pm 10 pm 8 hrs>当日白夜shifty
上午10时(第二天)-16小时-16小时prblm..8必须来到这里
任何想法请
或有人可以告诉我一种方法来检查收到的持续时间是否为负,例如
in my SQL server database I had all these three feilds swipein ,swipeout,duration as Time datatype ,and I want to insert these values there
For testing I give four values
Swipein Swipeout Duration(output displayed)
8 am 4 pm 8 hrs >>>>its same day sday shift
3 pm 10 pm 8 hrs >> same day daynight shifty
10 pm 6 am(next day) -16 hrs >>> the prblm..8 must come here
Any Idea pls
or can any one tell me an idea to check whether the duration recieved is negative like
if(duration <0)
{
duration= 24-duration;
}
推荐答案
不是使用time
数据类型,而是为什么不使用datetime
一起存储日期和时间.这样,即使日期更改,间隔也始终是正确的.
另一件事是,它确实需要存储持续时间.持续时间总是可以计算的,不建议在这种系统中存储计算的数据.如果需要,可以在表中创建一个计算列,也可以在SQL语句中或在客户端计算持续时间.
Instead of usingtime
data type why not usedatetime
to store the date and the time all together. This way the interval would always be correct even if the date changes.
Another thing is that is it really needed to store the duration. The duration can always be calculated and it''s not advisable to store calculated data in this kind of system. If you want you can create a computed column in the table or calculate the duration in SQL statements or at client side.
这篇关于时间间隔显示为负的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!