-1

我从数据库中提取的数据是(字符串,日期时间),我需要查看日期时间以查看它是否等于今天 @ 14:00 的 sysdate,但我无法弄清楚如何只查看列表中的日期时间字段。

int recordCount;

using (IDatabase db = SystemStatus.GetDatabase(_connectionStrings.stuff))
{
    const string query= @"
        SELECT DISTINCT string, date
        FROM table
        WHERE date > DATE_SUB(SYSDATE(), Interval 30 day) AND
              drop_date < DATE_SUB(NOW(), Interval 12 hour) AND 
              status_id = 2;";

    var records = db.Fetch<Dictionary<string, List<DateTime>>>(query);

    recordCount = records.Count;                               
}
4

1 回答 1

0

您需要一个日期时间对象进行比较:

DateTime now = DateTime.Now;
DateTime dt = new DateTime(now.Year, now.Month, now.Day, 14, 0, 0); // 2 PM today

您不需要“if”语句。您需要使用对象查询(LINQ)...

using System.Linq; 

// get everything past 2 PM today
var after2PMRecords = records.Where(r => r.Value > dt);

// get everything before 2 PM today
var before2PMRecords = records.Where(r => r.Value < dt);
于 2018-06-19T22:40:21.510 回答