当前位置:网站首页>Sqlite3数据库的timestamp类型的使用注意事项
Sqlite3数据库的timestamp类型的使用注意事项
2022-06-22 00:08:00 【Silent starry sky】
Sqlite3数据库的timestamp类型的使用注意事项
在Sqlite3中可以使用timestamp时间戳类型记录时间,但是在使用中发现几个容易被坑的地方,记录一下。
1.日期时间格式
不管是查询还是插入,对于timestamp字段则SQL语句中的日期时间格式必须是这样:“yyyy-MM-dd HH:mm:ss”。比如:“2022-06-09 10:00:00”,这是正确的,但是不能写成”2022-6-9 10:0:0“。写错后查询不到任何结果。
2.timestamp查询是必须要经过本地时间转化,否则查询的时间是错误的,比如要查询从2022-6-19 10:0:0到2022-6-19 15:0:0秒的记录则Where语句应该这样写:
WHERE DateTime(HisTime,‘localtime’) >= DateTime(‘2022-06-19 10:00:00’,‘localtime’) AND DateTime(HisTime,‘localtime’) <= DateTime(‘2022-06-19 15:00:00’,‘localtime’)
还有个方法,就是建立字段时设置初始值:DEFAULT (datetime(‘now’,‘localtime’)),就是用本地时间作为字段初始值,插入记录时可以不插入此时间字段,由数据库引擎自己初始为本地当前时间。
这里记录一下几个主要事项,防止下次再出现错误。
边栏推荐
猜你喜欢

Compilation principle - recursive descent subroutine method

pytorch学习13:实现LetNet和学习nn.Module相关基本操作

【DailyFresh】课程记录

Pytorch learning 05: indexing and slicing

03 FastJson 解决循环引用

pytorch学习01:梯度下降实现简单线性回归

Opérations de bits bits et

Pytorch learning 11:where and gather

如何使用物联网低代码平台进行报表管理?

小小协议大威力,数字化转型为何缺不了NVMe全闪存?
随机推荐
Graphical understanding of the article "text classification of Sina News Based on tensorflow+rnn"
Pat (a) - 1001 a+b format
English语法_副词_fairly / rather
调试中的虚变量和格式化字符
三种文件句柄之间的转换
isnull() ifnull() nullif()
Go Technology Daily (June 20, 2022) -- go: simple optimization notes
Version dynamic | exchangis 1.0.0-rc1 version release
[工程构建] cmake创建Release和Debug工程
数字化转型的下一个目标:提供准时制信息
Bit operation bit and
Li Kou daily question - day 24 -485 Maximum number of consecutive 1
[redis] install redis in Ubuntu and the basic usage and configuration of redis
手写数据库连接池
[environment stepping on pit] error occurs when uploading files using fastdfs test
0x00007ffff3d3ecd0 in Io Vfprintf Interne (S = 0x7ffff40b5620 < io 2 1 stdout >
Pre add post add exploration and function call exploration
Pytorch learning 09: basic matrix operations
Meetup03 review: introduction to the new version of linkis and the application practice of DSS
[environment stepping on the pit] open the picture with OpenCV and report an error