//比较DateTime类型
DateTime dt1=DateTime.Now;
DateTime dt2=Convert.ToDateTime ("2006-11-09 18:04:11");
if(dt1.CompareTo (dt2)< 0) //CompareTo:0-两者相等
Response.Write ("<script>alert(\"dt1<dt2\");</script>");
else
Response.Write ("<script>alert(\"dt1>dt2\");</script>");
//比较string
DateTime dt3=DateTime.Now ;
string strdt3=dt3.ToString ("yyyy-MM-dd HH:mm:ss");
string strdt4="2006-11-09 18:04:11";
//字符串比较时,主要把时间都转换成yyyy-MM-dd HH:mm:ss的格式
if (strdt3.CompareTo(strdt4)<0)//CompareTo:0-两者相等
Response.Write ("<script>alert(\"strdt3<strdt4\");</script>");
else
Response.Write ("<script>alert(\"strdt3>strdt4\");</script>");
DateTime dt1=DateTime.Now;
DateTime dt2=Convert.ToDateTime ("2006-11-09 18:04:11");
if(dt1.CompareTo (dt2)< 0) //CompareTo:0-两者相等
Response.Write ("<script>alert(\"dt1<dt2\");</script>");
else
Response.Write ("<script>alert(\"dt1>dt2\");</script>");
//比较string
DateTime dt3=DateTime.Now ;
string strdt3=dt3.ToString ("yyyy-MM-dd HH:mm:ss");
string strdt4="2006-11-09 18:04:11";
//字符串比较时,主要把时间都转换成yyyy-MM-dd HH:mm:ss的格式
if (strdt3.CompareTo(strdt4)<0)//CompareTo:0-两者相等
Response.Write ("<script>alert(\"strdt3<strdt4\");</script>");
else
Response.Write ("<script>alert(\"strdt3>strdt4\");</script>");