如何在SqlServer数据库中用SQL语句中比较时间

2025-02-23 13:02:04
推荐回答(2个)
回答1:

datediff()这个挺好用的,select
datediff(time1,time2,month)
from
a,time1和time2两个字段必须是时间字段

回答2:

你时间转换部分有错。。。
string
sql
=
"select
count(*)
from
Table
where
UserId
=
'"
+
userId
+
"'
and
SignTime
>
'"+
Convert.ToDateTime(onDutyTime
)+"'
and
SignTag=1
and
SignTime
between
'"+Convert.ToDateTime(beginTime)+"'
and
'"+Convert.ToDateTime(endTime)+"'
";
你看这样行不???