close

遇到這個問題

原本下面的dtNow是用DateTime.Now

會造成當日的判斷有些問題,如開始與結束同一天會走到flag=fase

改成DateTime.Today再比較即可解決

筆記一下!

Sample Code:

 

Boolean flag = false; ;
DateTime start = Convert.ToDateTime(dt.Rows[0]["StartDate"]);
DateTime end = Convert.ToDateTime(dt.Rows[0]["EndDate"]);
DateTime dtNow = DateTime.Today;
if ((DateTime.Compare(start, dtNow) <= 0) && (DateTime.Compare(end, dtNow) >= 0))
{
//在起始日與結束日內(含到期日)
flag = true;
}
else
{
flag = false;
}
view raw gistfile1.txt hosted with ❤ by GitHub
arrow
arrow
    全站熱搜
    創作者介紹
    創作者 Kenny Lin 的頭像
    Kenny Lin

    Kenny的程式筆記

    Kenny Lin 發表在 痞客邦 留言(1) 人氣()