我正在尝试将我的值按升序排序,但是虽然我得到了结果,但它没有正确排序,如下所示:
"50","2016-12-1","2016-12-01 17:42:30","2016-12-01 17:42:30","0","0"
"50","2016-12-10","2016-12-10 07:31:43","2016-12-10 07:31:43","0","0"
"50","2016-12-11","2016-12-11 04:27:35","2016-12-11 04:27:35","0","0"
"50","2016-12-12","2016-12-12 07:52:18","2016-12-12 18:02:47","10","10"
"50","2016-12-13","2016-12-13 07:28:22","2016-12-13 18:18:31","10","50"
"50","2016-12-14","2016-12-14 07:32:34","2016-12-14 18:37:09","11","4"
"50","2016-12-15","2016-12-15 07:14:15","2016-12-15 07:14:15","0","0"
"50","2016-12-2","2016-12-02 07:23:33","2016-12-02 17:37:22","10","13"
"50","2016-12-3","2016-12-03 07:49:27","2016-12-03 17:45:01","9","55"
"50","2016-12-5","2016-12-05 07:40:22","2016-12-05 17:32:29","9","52"
"50","2016-12-6","2016-12-06 07:41:43","2016-12-06 17:42:00","10","0"
"50","2016-12-7","2016-12-07 07:20:33","2016-12-07 17:40:51","10","20"
"50","2016-12-8","2016-12-08 07:22:02","2016-12-08 20:56:37","13","34"
"50","2016-12-9","2016-12-09 07:35:06","2016-12-09 18:11:18","10","36"
2016-12-2低于2016-12-15。这就是我得到这个值的方法:
SELECT uid, scan_date as 'Date' , min(scan_time) as 'Time In', max(scan_time) as 'Time
CAST(((strftime('%s', max(scan_time)) - strftime('%s', min(scan_time))) % (60 * 60 * 24)) / (60 * 60) AS TEXT) as Hours,
CAST((((strftime('%s', max(scan_time)) - strftime('%s', min(scan_time))) % (60 * 60 * 24)) % (60 * 60)) / 60 AS TEXT) as Minutes
FROM tbl_scanTimes
GROUP BY uid, scan_date
ORDER BY uid asc, scan_date
这是我将数据插入sqlite
的方法var sCommand = new StringBuilder(@"REPLACE INTO tbl_scanTimes(branch, uid, scan_date, scan_time) VALUES ");
sCommand.Append(string.Join(",", (from DataRow row in values.Rows
let branch = _yard
let empId = row[0].ToString().Trim()
let scanTime = row[1].ToString().Trim()
let date = Convert.ToDateTime(scanTime)
let oDate = date.Year+"-"+date.Month+"-"+date.Day
select string.Format("('{0}','{1}','{2}','{3}')", branch, empId, oDate, scanTime)).ToArray()));
sCommand.Append(";");
有没有办法可以在2016-12-1的那一天放0,这样2016-12-01?谢谢。
答案 0 :(得分:1)
关于supported date formats的 CL 评论,我认为您的数据插入可能正在使用您的桌面日期格式设置,因为您正在传递{{1}在格式字符串中只是'{2}'。
插入数据时尝试使用此格式:
oDate
(是的,我知道它可以打包到{2} expr中,我只是希望它能脱颖而出)。
顺便说一句。注意大写的MM和HH。这很重要。
Here's the full list
无论它是否有效,请仔细检查您要发送给数据库的实际查询。在该行上放置一个断点,看看Format()方法产生了什么。