標籤:
--格林威治日期時間,比北京時間晚8小時select datetime(‘now‘);--格林威治日期select date(‘now‘);--本地時間select time(‘now‘,‘localtime‘);--日期時間格式化select strftime(‘%Y-%m-%d %H:%M:%S‘,‘now‘,‘localtime‘);--加1小時select datetime(date(‘now‘),‘+1 hour‘);--加1小時30分鐘select datetime(date(‘now‘),‘+1 hour‘,‘+30 minute‘);--當月最後一天select date(‘now‘,‘localtime‘,‘start of month‘,‘+1 month‘,‘-1 day‘);--當月1號select date(‘now‘,‘localtime‘,‘start of month‘);--下月1號select date(‘now‘,‘localtime‘,‘start of month‘,‘+1 month‘);--截取字串(第2個參數為從1算起的開始位置,第3個位置為截取長度):結果為123select substr(‘abc123‘,4,3);--計算長度,結果為6select length(‘abc123‘);--返回小寫、大寫,結果為abc,ABCselect lower(‘abC‘),upper(‘abC‘);--四捨五入保留2位小數select round(cast(1 as double)/cast(3 as double),2);--case when用法selectcase when cast(strftime(‘%H‘,‘now‘,‘localtime‘) as int) >= 6 and cast(strftime(‘%H‘,‘now‘,‘localtime‘) as int) <=12 then ‘上午‘ when cast(strftime(‘%H‘,‘now‘,‘localtime‘) as int) >12 and cast(strftime(‘%H‘,‘now‘,‘localtime‘) as int) <=18 then ‘下午‘ when cast(strftime(‘%H‘,‘now‘,‘localtime‘) as int) >18 and cast(strftime(‘%H‘,‘now‘,‘localtime‘) as int) <=23 then ‘晚上‘ else ‘淩晨‘ end;
SQLite一些函數用法