SQLite一些函數用法


--格林威治日期時間,比北京時間晚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個位置為截取長度):結果為123
select substr('abc123',4,3);

--計算長度,結果為6
select length('abc123');

--返回小寫、大寫,結果為abc,ABC
select lower('abC'),upper('abC');

--四舍五入保留2位小數
select round(cast(1 as double)/cast(3 as double),2);

--case when用法
select
case 
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; 

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM