当前位置:网站首页>Precautions for using timestamp type of SQLite3 database

Precautions for using timestamp type of SQLite3 database

2022-06-22 01:12:00 Silent starry sky

Sqlite3 Database timestamp Precautions for the use of types

stay Sqlite3 Can be used in timestamp The timestamp type records the time , But in the course of use, we found several places that were easy to be damaged , Make a note of .
1. Date time format
Whether it's a query or an insert , about timestamp Field rule SQL The date time format in the statement must be like this :“yyyy-MM-dd HH:mm:ss”. such as :“2022-06-09 10:00:00”, That's right , But it can't be written as ”2022-6-9 10:0:0“. No result can be found after the error is written .
2.timestamp Queries must go through local time conversion , Otherwise, the query time is wrong , For example, to query from 2022-6-19 10:0:0 To 2022-6-19 15:0:0 The second record is Where The sentence should be written like this :
WHERE DateTime(HisTime,‘localtime’) >= DateTime(‘2022-06-19 10:00:00’,‘localtime’) AND DateTime(HisTime,‘localtime’) <= DateTime(‘2022-06-19 15:00:00’,‘localtime’)
There's another way , This is to set the initial value when creating a field :DEFAULT (datetime(‘now’,‘localtime’)), The local time is used as the initial value of the field , You can insert a record without inserting this time field , The database engine will initially set the local current time .
Here are a few main things to note , Prevent errors next time .

原网站

版权声明
本文为[Silent starry sky]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/173/202206220008116798.html