计算引擎中使用系统自动计算参数:@time_calc
直接上代码:
/// <summary> /// auto_do_for_time_calc 按照秒计算 /// @time_calc-86400 返回则是当前时刻往前减去86400秒(也就是一天),可用:@time_calc-200,@time_calc+500,@time_calc300 /// select * from table where create_time>'@time_calc-18000000' and create_time<'@time_calc-36000' /// select * from table where create_time>'2024-04-17 03:26:14' and create_time<'2024-11-11 01:26:14' /// </summary> /// <param name="sql"></param> /// <returns></returns>
string auto_do_sql_for_time_calc(string sql) { if (sql.contains_x("@time_calc").is_false()) return sql; Regex regex = new Regex("@time_calc[\\w\\W]*?(?=')"); var matches = regex.Matches(sql); foreach (Match match in matches) { string key = match.Value; double val = key.Replace("@time_calc", "").ToDouble(); sql = sql.Replace(key, DateTime.Now.AddSeconds(val).toStringX()); } return sql; }
done