我有两个不同的日期时间:2020-05-18 12:30:01
和2020-05-17 13:00:00
。
我想说明的格式它们之间的时间差HH:MM:SS
,这是23:30:01
。
如果差异大于24小时,例如28小时12分45秒,则显示为28:12:45
。
如何在SQLite中做到这一点?
SQLite支持有限数量的日期时间操作功能。
这些功能之一是strftime()
和
strftime('%s', somedate)
返回从'1970-01-01'
到的秒数somedate
。
通过使用此功能,算术计算,字符串填充和串联,您可以像这样获得所需内容:
CASE WHEN ((strftime('%s', date1) - strftime('%s', date2)) / 3600) < 10 THEN '0' ELSE '' END ||
((strftime('%s', date1) - strftime('%s', date2)) / 3600) || ':' ||
SUBSTR('0' || (((strftime('%s', date1) - strftime('%s', date2)) / 60) % 60), -2) || ':' ||
SUBSTR('0' || ((strftime('%s', date1) - strftime('%s', date2)) % 60), -2)
用您的日期替换date1
和date2
。
请参阅简化的演示。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句