示例数据字段如下:
DATE+05/06/2022 23:59:59;
DATE+06/05/2022 23:59:59;
DATE+14/05/2022 23:59:59;
DATE+26/05/2022 23:59:59;
我们在日期中的SUBSTR数据为:
05/06/2022 23:59:59
06/05/2022 23:59:59
14/05/2022 23:59:59
26/05/2022 23:59:59
必填日期字段如下:
2022-06-05 23:59:59
2022-05-06 23:59:59
2022-05-14 23:59:59
2022-05-26 23:59:59
我尝试过的填充NULL作为最终结果的方法:
- 铸造到日期时间[
CAST('05/06/2022 23:59:59' as datetime)
] - 日期时间((的使用[
datetime('05/06/2022 23:59:59')
] - 使用strftime(([
strftime('%Y-%m-%d %H:%M:%S','05/06/2022 23:59:59')
]
我发现的不相关的链接:
- https://stackoverflow.com/a/4429028/2517880
- https://www.tutlane.com/tutorial/sqlite/sqlite-strftime-function
我正在寻找除拆分和连接日期字段之外的任何其他方法。
SQLite没有将字符串转换为日期的内置函数。您需要使用字符串函数来重新组合日期。
对于lke:'DATE+05/06/2022 23:59:59;'
格式,可以执行:
substr(mycol, 12, 4)
|| '-' || substr(mycol, 9, 2)
|| '-' || substr(mycol, 6, 2)
|| ' ' || substr(mycol, 17, 8)
DB Fiddle上的演示:
with mytable as (
select 'DATE+05/06/2022 23:59:59;' mycol
union all select 'DATE+06/05/2022 23:59:59;'
union all select 'DATE+14/05/2022 23:59:59;'
union all select 'DATE+26/05/2022 23:59:59;'
)
select substr(mycol, 12, 4)
|| '-' || substr(mycol, 9, 2)
|| '-' || substr(mycol, 6, 2)
|| ' ' || substr(mycol, 17, 8) mydate
from mytable
|mydate||:------------------||2022-06-05 23:59:59||2022-05-06 23:59:59||2022-05-14 23:59:59||2022-05-26 23:59:59 |