将timeofday与存储在DB中的日期时间进行比较 [英] Comparing timeofday with datetime stored in DB
问题描述
我正在研究一个项目,它记录了员工的登录时间。
班次已经定义了开始时间和结束时间(存储在DB到DateTime字段中)
来自DateTimePicker.value的
(它还存储日期和时间,这是不必要的)
当员工登录时,我需要检查他是否是上班时间或晚上等。
我将按照以下方式进行比较
Hi,
I am working on a project, which records the login time of employees.
Shifts have been defined with starting time and ending time (stored in DB to DateTime field)
from DateTimePicker.value (it also stores date with time, which is unnecessary)
When employee logs in, I need to check if he is intime or late etc.
I am comparing it in the following way
If TimeOfDay >= DateTime.Parse(DsReadShift.tblShift.Rows(0).Item("StartTime")) And DateTime.Now <= DateTime.Parse(DsReadShift.tblShift.Rows(0).Item("EndTime")) Then
vrStatus = "Logged In"
End If
但它不起作用。我假设应该有一些方法来忽略相关的日期,只有时间应该比较。但我不知道怎么做。
我是否以正确的方式在DB中存储时间?
请指教。
谢谢
But it does not work. I assume there should be some way to ignore date associated and only time should be compare. But I do not know how.
Am I storing time in right way in the DB?
Please advise.
Thanks
推荐答案
If FormatDateTime(TimeOfDay,DateFormat.ShortTime) >= FormatDateTime(DateTime.Parse(DsReadShift.tblShift.Rows(0).Item("StartTime")),DateFormat.ShortTime) And formatdatetime(DateTime.Now,DateFormat.ShortTime) <= formatdatetime(DateTime.Parse(DsReadShift.tblShift.Rows(0).Item("EndTime")),DateFormat.ShortTime) Then
vrStatus = "Logged In"
End If
对我有用..
works for me..
这篇关于将timeofday与存储在DB中的日期时间进行比较的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!