ACCESS数据库中有字段id(数字型),date(日期型,yyyy-mm-dd hh:nn:ss),
id date
1 2005-6-1 13:12:12
2 2005-6-2 12:12:34
3 2005-6-2 12:14:34
比如今天是6月2日,如何查找今天的数据条数?
select count(id) from table where date=Now() 有错误!
id date
1 2005-6-1 13:12:12
2 2005-6-2 12:12:34
3 2005-6-2 12:14:34
比如今天是6月2日,如何查找今天的数据条数?
select count(id) from table where date=Now() 有错误!
要是c#里面的话
exestr="select count(id) from table where date='"+
System.DateTime.Now.Date.ToString()+"'";要是写在sql server里面的话
select count(id) from table where date=CURRENT_TIMESTAMP
exestr="select count(id) from table where date='"+
System.DateTime.Now.Date.ToString()+"'";
提示类型不匹配!我数据库中的类型是yyyy-mm-dd hh-nn-ss,而System.DateTime.Now.Date.ToString()是string型,换成System.DateTime.Now.Date页不对select count(id) from table where date=getdate()
提示找不到getdate()
select count(id) from table where datepart("d",date)=datepart("d",Now())
这样查找出来的数据显然不对,今天是2005-6-3,那么它还会把2005-5-3,2003-6-3满足的都找出来
试试!
"select count(id) from table where date like '_"+dt.year+"-"+dt.Month+"-"+dt.Day+"_'";
这个是正确的,但是感觉很繁琐.有没有简单一点的查询.下面这条查出来数据是0,为什么? 看样子like在这里行不通
string today = System.DateTime.Now.ToString("yyyy-M-d");
string strSel = "select count(id) as today_reply from reply where date like '" + today + "'";
string sql = "select count(id) as today_reply from reply where date between '" + tempTime.ToShortDateString() + "' and '" + tempTime.AddDays(1).ToShortDateString() + "'";
试一下
select count(id) from table where
CONVERT(char(12),[date], 2) = CONVERT(char(12),getdate(), 2)