C#比較時分秒大小,終止分鐘默認加十分鐘,解決跨天、跨月、跨年的狀況

   private void cmbInHostimes_SelectedIndexChanged(object sender, EventArgs e)
        {
            DataRow[] dr;
            if (chkMid.Checked == true)
            {
                dr = leaveHosRecordData.Tables[0].Select("INHOSTIMES = " + cmbInHostimes.Text, "CURRENTINHOSMARK");
            }
            else
            {
                dr = leaveHosRecordData.Tables[0].Select("CURRENTINHOSMARK = " + cmbInHostimes.Text, "CURRENTINHOSMARK");
            }

            if (dr.Length > 0)
            {
                txtStartDate.DateTime = Convert.ToDateTime(dr[0]["ENTERHOSDATE"]);
                txtStartTime.Time = Convert.ToDateTime(Convert.ToDateTime(dr[0]["ENTERHOSDATE"]).ToString("yyyy-MM-dd") + " 00:00:00");
                txtEndTime.Time = Convert.ToDateTime(dr[dr.Length - 1]["LEAVEHOSDATE"]).AddMinutes(10);
                currentInHosMark1 = Convert.ToInt32(dr[0]["CURRENTINHOSMARK"]);
                //Case#28375
                DateTime leavehosDate = Convert.ToDateTime(dr[dr.Length - 1]["LEAVEHOSDATE"]);//出院時間
                TimeSpan ts1 = new TimeSpan(leavehosDate.Hour, leavehosDate.Minute, leavehosDate.Second);
                TimeSpan ts2 = new TimeSpan(23, 49, 59);
                //比較時分秒大小
                if (ts1 > ts2)
                {
                    txtEndDate.DateTime = Convert.ToDateTime(dr[dr.Length - 1]["LEAVEHOSDATE"]).AddDays(1);
                }
                else
                {
                    txtEndDate.DateTime = Convert.ToDateTime(dr[dr.Length - 1]["LEAVEHOSDATE"]);
                }              
            }
        }
相關文章
相關標籤/搜索