Click here to Skip to main content
15,896,912 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
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

C#
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


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
Posted

1 solution

VB
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..
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900