1、SQLite中的datetime类型在库中以字符形式存储,因此为节省空间可以用整型类型存时间戳;

2、比较datetime类型:字段名称 >= '2019-04-09 09:00:00'

3、datetime转换为unix时间戳:strftime('%s',字段名称或'2019-04-09 09:00:00','-8 hour'),// 注意,字段名称莫加单引号

4、unix时间戳转换为datetime: datetime(字段名称或'1568098860','unixepoch','localtime')// 注意,字段名称莫加单引号

5、取当前时间字符串:select datetime('now', '+8 hour');

6、以指定的格式输出datetime类型字段:select createtime,strftime('%Y%m%d%H%M%S',createtime) from mytable;//输出yyyymmddHHMMSS格式

7、取时间中的小时:select createtime from mytable where strftime('%H',createtime) in ('00','04','08','12','16','20');

相关文章:

  • 2021-07-05
  • 2022-12-23
  • 2022-01-14
  • 2022-01-21
  • 2022-01-22
  • 2021-05-27
  • 2021-11-15
  • 2022-12-23
猜你喜欢
  • 2021-06-04
  • 2022-02-25
  • 2022-12-23
  • 2022-12-23
  • 2021-12-28
  • 2022-12-23
相关资源
相似解决方案