2014.12.17 15:28

C# DateTime 값 비교.

 //시간변환
                        DateTime Time1 = Convert.ToDateTime(DateTime.Now.ToString("yyyy/MM/dd"));

                       //오늘시간을 convert 해서 compare 로 비교할수있도록 해준다.
                        DateTime Time2 = Convert.ToDateTime(DbReader.GetString(4));

                       


                      if (DateTime.Compare(Time1, Time2) > 0)  // time1 > time2 오늘날자보다 작을경우
                        {
                            Label1.Text += "<a><font color=red>" + DbReader.GetString(4) + "</font></a>";
                        }

                        else if (DateTime.Compare(Time1, Time2) == 0) // time1 == time2 오늘날자와 같을경우
                        {
                            Label1.Text += "<a>" + DbReader.GetString(4) + "</a>";
                        }

                        else if (DateTime.Compare(Time1, Time2) < 0) // time1 < time2 오늘날자 보다 클경우
                        {
                            Label1.Text += "<a><font color=green>" + DbReader.GetString(4) + "</font></a>";
                        }
                        else
                        {
                            continue;
                        }

Trackback 0 Comment 0