【发布时间】:2014-07-18 09:45:44
【问题描述】:
Dapper 返回日期类型列的格式与存储在数据库中的格式不同。
数据库中的格式----> 2012-05-19 15:27:00.000
dapper 返回 --------> 19-05-2012 15:27:00.000
var l = this.db.Query<myObject>("select id, received from myTable where( received between @d1 and @d2)",
new { @d1 = d1, @d2 = d2, }).ToList();
string d1 = 2011-01-18 00:00:00
string d2 = 2014-07-18 23:59:59
public class myObjectIs
{
public string id { get; set; }
public string received { get; set; }
}
已收到 - 数据时间类型列
Dapper 是否有预定义的日期类型格式来返回? 如果是,如何更改?
谢谢。
【问题讨论】:
-
如果数据库中的数据类型是日期,不用管它。 c# 有可用的日期格式化工具。使用一个。
-
DateTime 值没有格式。是您的程序以“格式”显示 DateTime 值 但是,如果字段
received是日期,为什么要将其存储在字符串中?改用 DateTime 变量 -
数据库中的日期时间没有格式;这是一个数字。您是否将其存储为字符串?还是作为日期时间?
-
另外:这里的
d1和d2究竟是什么?他们是string?或DateTime?再说一遍:究竟received列的定义类型是什么? -
更新了我的 qyestion:d1 和 d2 是字符串,接收是数据时间