日期:2014-05-16  浏览次数:20445 次

datetime和date类型
    今天在项目中遇到一个比较日期的问题,数据库字段的类型是datetime,但是我只想比较日期,不想要时间.然后就转换啊转换啊,一顿整.转成了标准date string类型然后去比较.结果我发现我搞糊涂了一个概念.datetime和date是不一样的东西.date没有时间只有日期.一般的日期比较应该用date而不是用datetime,需要精确到时间的比较才用datetime.
   不仅仅是数据库.我在C#里面比较日期的时候我也不想比较日期.然后我又没发现有DateTime.Now有忽略时间的方法.结果我还是搞混了datetime和date.C#的DateTime有个方法:
DateTime.Date Property
public DateTime Date { get; }

Gets the date component of this instance.

Type: System.DateTime
A new object with the same date as this instance, and the time value set to 12:00:00 midnight (00:00:00).