c#中oracle的to_date函数使用方法
内容摘要
例子一,获取三小时前的记录
public static DataTable Query()
{
const string sSql = "select xh,lsh,name from table where gxsj>to_date(:gxsj,'yyyy-MM-dd HH24:mi
public static DataTable Query()
{
const string sSql = "select xh,lsh,name from table where gxsj>to_date(:gxsj,'yyyy-MM-dd HH24:mi
文章正文
例子一,获取三小时前的记录
public static DataTable Query() { const string sSql = "select xh,lsh,name from table where gxsj>to_date(:gxsj,'yyyy-MM-dd HH24:mi:ss')"; OracleParameter[] parameters = {new OracleParameter(":gxsj", OracleType.VarChar, 10)}; parameters[0].Value = DateTime.Now.AddHours(-3).ToString("yyyy-MM-dd HH") + ":00:00"; return DBUtility.DbHelperOra.Query(sSql, parameters).Tables[0]; }
例子二,获取大于当前时间的记录
public static string GetHphm(string sClsbdh) { const string sSql = "select name from table where sj>to_date(:yxsj,'yyyy-MM-dd')"; OracleParameter[] paramters = {new OracleParameter("sj", OracleType.VarChar, 10)}; paramters[0].Value = DateTime.Now.ToString("yyyy-MM-dd"); using (var mReader = DbHelperOra.ExecuteReader(sSql, paramters)) { if (mReader.Read()) { return mReader["name"].ToString(); } } return ""; }
代码注释