数据库表里有个datetime字段 怎么判断这个时间与当前时间如果相差三天就在aspx页面弹出右下角提示框
读数据库对比下获取结果复制给一个全局变量,将这个全局变量用<%%>赋值给aspx页面script标签中的js变量,然后js判断下弹出你需要的框
select count(id) from table where datediff(d,时间字段,getdate())=3 ...其他条件
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
string connStr = "Server=.;Database=Test;uid=sa";
SqlConnection conn = new SqlConnection(connStr);
SqlCommand comm = new SqlCommand("select NowDt from Table1 where DtId = 1", conn);
System.DateTime aa;//数据库中存的时间
System.DateTime bb;//当前时间
//取数据库中时间,字段是varChar类型
try
{
conn.Open();
aa = Convert.ToDateTime(comm.ExecuteScalar().ToString());//数据库时间,object转为string转换为DateTime
conn.Close();
}
catch(Exception exp)
{
throw exp;
}
finally
{
conn.Dispose();
comm.Dispose();
}
bb = System.DateTime.Now;//当前时间
TimeSpan ts1 = new TimeSpan(bb.Ticks);
TimeSpan ts2 = new TimeSpan(aa.Ticks);
TimeSpan ts = ts1.Subtract(ts2).Duration();//求时间差的绝对值
if( ts.Days>3)
{
//前台页面中某个div弹出来,从右下角
}
}