sql 涉及時間

2021-08-02 20:52:14 字數 775 閱讀 6716

獲取今天的資料

select * from table_name where to_days (field_name) = to_days(now())

獲取昨天的資料

select *from table_name where to_days(now)-todays(field_name)=1

獲取昨天到今天的資料

select *from ding_personnel_corp c where (to_days(now())-to_days(field_name)) <=1

獲取近7天的資料

select *from table_name where date_sub(curdate(),intervel 7 day) <= date(field_name)

獲取本週資料

select *from table_name where yearweek(date_format(field_name,'%y-%m-%d')) = yearweek(now());

獲取上週資料

select *from table_name where yearweek(date_format(field_name,'%y-%m-%d')) = yearweek(now())-1;

查詢距離現在6個月的資料

elect

*from user_event where create_time between date_sub(now(),interval 6

month) and

now();

處理涉及時區的問題

1.有時會出現這樣的問題,本地 跑的很正常,到了伺服器上卻出現了問題,而且這種問題每次還很棘手,不好定位,這種問題很多都是因為時區不一致導致的 2.對於涉及時區的問題,都應該使用pyzt模組來解決,這個python包提供了奧爾森時區資料庫,這也是許多語言和作業系統所使用的時區資訊標準。3.pyzt模...

CALayer及時間模型

我們都知道uiview是mvc中的view.uiview的職責在於介面的顯示和介面事件的處理.每乙個view的背後都有乙個layer 可以通過view.layer進行訪問 layer是用於介面顯示的.calayer屬於quartzcore框架,非常重要,但並沒有想象中的那麼好理解.我們通常操作的用於...

Mysql Date format 及時間相關用法

d 有英語字首的月份的日期 1st,2nd,3rd,等等。y 年,數字,4 位 y 年,數字,2 位 a 縮寫的星期名字 sun sat d 月份中的天數,數字 00 31 e 月份中的天數,數字 0 31 m 月,數字 01 12 c 月,數字 1 12 b 縮寫的月份名字 jan dec j 一...