SQLite - 時間



現在時間


select datetime('now','localtime')
select CURRENT_TIMESTAMP;



目前時間換成秒數


SELECT strftime('%s', CURRENT_TIMESTAMP);



秒數換成時間格式(xxxx-xx-xx 00:00:00)


select datetime(1688569059, 'unixepoch');



抓這個月份的最後一天日期(xxxx-xx-xx)


select date('2024-02-02','start of month','+1 month','-1 day');



時間抓取


SELECT strftime('%Y-%m-%d %H:%M:%S %w %W', CURRENT_TIMESTAMP);

%Y:年份
%m:月份
%d:日期
%H:小時
%M:分鐘
%S:秒數
%w:星期 (0:Sun, 1:Mon, ...)
%W:週數 (Week of year, 01-53)
%j:天數 (Day of year, 001-366)
%s:目前時間的秒數 (seconds since 1970-01-01 00:00:00 UTC)


目前時間-60分的時間格式(xxxx-xx-xx 00:00:00)


datetime(strftime('%s','now')-3600, 'unixepoch')
datetime(strftime('%s','now'), 'unixepoch', '-60 minutes')



時間差


SELECT (julianday(datetime('now','localtime')) - julianday('2022-09-27 11:35:13')) * 86400.0

julianday 返回公元前4714年11月24日格林威治中午以來的天數分數


strftime('%s', Time1)-strftime('%s', Time2)





沒有留言:

張貼留言