2011-02-16 16 views
-1
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; 
     } 
    } 
} 
+1

你這個究竟是什麼,你需要,請編輯和按您需要 – Dotnet 2011-02-16 05:30:55

回答

0

比較登錄時間,退出時間退出time.logout必除登錄時間時,你會想用DateTime.Compare method

它需要兩個參數(一個DateTime對象的兩個實例進行比較),並返回一個整數,指示第一個是早於,晚於還是晚於第二個。

如果第一次更早,返回值將小於0.如果兩個時間值相同,則返回值將爲0.如果第一次更晚,返回值將大於零。

示例代碼:

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