SQL中判断时间范围可以用datediff方法,示例代码:
public static DataSet GetResult(string strRoleSort, string strUserID, string strFirstTime, string strLastTime,string strRoleState)
{
string sql = " select * from t_role where delete_flag = " + WebDefine.DeleteN
+ " and len(role_number) = 12 and role_state = " + strRoleState;
if (strRoleSort != "" && strRoleSort != null)
{
sql += " and role_sort = " + strRoleSort;
}
if (strUserID != "" && strUserID != null)
{
sql += " and accepte_id = '" + strUserID + "'";
}
if (strFirstTime != "" && strFirstTime != null)
{
sql += " and datediff(day,create_time,'" + strFirstTime + "') <= 0 ";
}
if (strLastTime != "" && strLastTime != null)
{
sql += " and datediff(day,create_time,'" + strLastTime + "') >= 0 ";
}
return DBEngine.ExecuteSql(WebDefine.DbConnectionName,sql);
}