开发者

how to compare login time and logout time.logout time must greater than login time using timepicker [closed]

开发者 https://www.devze.com 2023-02-11 05:55 出处:网络
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical andcannot be reasonably answered in its current form. For help clari
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reope开发者_高级运维ned, visit the help center. Closed 11 years ago.
if (Convert.ToDateTime(GrdEmployeeAttendance.CurrentRow.Cells["LoginTime"].Value) < Convert.ToDateTime(GrdEmployeeAttendance.CurrentRow.Cells["LogoutTime"].Value))
{
    if (GrdEmployeeAttendance.Columns[e.ColumnIndex].Name == "LoginTime")
    {
        GrdEmployeeAttendance.EndEdit();

        if (Convert.ToDateTime(GrdEmployeeAttendance.CurrentRow.Cells[e.ColumnIndex].Value) < Convert.ToDateTime("01:00 PM"))
        {
            GrdEmployeeAttendance.CurrentRow.Cells["CheckFN"].Value = true;
        }
        else
        {
            GrdEmployeeAttendance.CurrentRow.Cells["ChkAN"].Value = true;
        }
    }
}


To compare the login time to the logout time, you will want to use the DateTime.Compare method.

It takes two arguments (the two instances of a DateTime object to be compared), and returns an integer that indicates whether the first is earlier than, the same as, or later than the second.

If the first time is earlier, the return value will be less than 0. If the two time values are the same, the return value will be 0. If the first time is later, the return value will be greater than zero.

Sample code:

DateTime date1 = new DateTime(2009, 8, 1, 0, 0, 0);
DateTime date2 = new DateTime(2009, 8, 1, 12, 0, 0);
int result = DateTime.Compare(date1, date2);
string relationship;

if (result < 0)
   relationship = "is earlier than";
else if (result == 0)
   relationship = "is the same time as";         
else
   relationship = "is later than";

Console.WriteLine("{0} {1} {2}", date1, relationship, date2);

// The example displays the following output:
//    8/1/2009 12:00:00 AM is earlier than 8/1/2009 12:00:00 PM
0

精彩评论

暂无评论...
验证码 换一张
取 消