mysql常用時間函式

2021-10-02 06:47:08 字數 788 閱讀 2041

mysql常用的日期函式及用法如下:

#當前時間

select now();   #結果:2020-01-18 15:25:26

#當前時間戳

select current_timestamp;  #結果:2020-01-18 15:26:36

select current_timestamp();  #結果:2020-01-18 15:26:36

#前一天 

select date_add(now(), interval -1 day);  #結果:2020-01-17 15:27:13

#後一天

select date_add(now(), interval  1 day);  #結果:2020-01-19 15:27:39

可用引數:hour、minute、second、microsecond、week、month、quarter、year

#日期格式化

select date_format('2020-1-18 15:28:19', '%y%m%d%h%i%s');  #結果:20200118152819

#字串轉換為日期

select str_to_date('20200118152819', '%y%m%d%h%i%s');

#獲取unix時間戳

select unix_timestamp();  #結果: 1579332593

#字串轉unix時間戳

select unix_timestamp('2020-1-18 15:30:41');   #結果:1579332641

常用時間函式

比較常用的時間函式有time localtime asctime 和gmtime 函式time 的原型為 time t time time t time 函式time 返回系統的當前日曆時間,如果系統丟失時間設定,則函式返回 1。對函式time的呼叫,既可以使用空指標,也可以使用指向time t型別...

MySQL常用時間函式詳解 推薦

2.6 date sub date add date sub date,interval expr type date 引數是合法的日期表示式。expr 引數是您希望新增的時間間隔。select id from my table where create time date sub now inte...

php 常用時間函式

php時間 time 來取得伺服器當前時間的時間戳 expiration time 2 3600 得到當前時間延遲2小時候的時間戳 失效驗證 略 計算當前頁面執行時間的例子 do something sleep 3 do something running time time server requ...