MYSQL時間戳轉換函式DATE FORMAT使用

2021-10-10 12:44:08 字數 715 閱讀 9319

一、data_format轉換函式將13位biglnt型別的資料時間戳轉為「年月日時分秒」;

資料庫中時間型別是13位bigint型別的資料;

select date_format(from_unixtime(列名/1000),』%y%m%d』) from xx表;

原理就是把13位的時間格式/1000等於時間戳,使用from_unixtime函式把時間戳轉換成具體的日期;

二、將時間「年月日」轉換為時間戳;

將時間轉換為時間戳,select unix_timestamp(『2018-08-30 19-40-07』),如果引數為空,則處理為當前時間,mysql中使用unix_timestamp和from_unixtime可以不用指定日期型別;

三、mysql 時間格式化 date_format使用;

select * from tablename a

where a.time between date_format(#,』%y-%m-%d %h:%i:%s』) and date_format(#,』%y-%m-%d %h:%i:%s』)

date_format將傳來的date型別轉為自己需要的格式,如%y-%m-%d %h:%i:%s會將傳來的starttime和endtime轉為"yyyy-mm-dd hh:mm:ss"格式;

MySQL 日期函式 轉換時間戳

from unixtime unixtime,format 用途 將數字型的unix 時間日期值轉為de日期值 引數說明 unixtime bigint型別,秒數,unix格式的日期時間值,若輸入為string,double型別會隱式轉換為bigint後參與運算。根據format格式化。如果form...

MySql時間戳函式

mysql時間戳涉及的函式 date format date,format 函式,mysql日期格式化函式date format unix timestamp 函式 str to date str,format 函式 from unixtime unix timestamp,format 函式,my...

時間戳轉換日期 日期轉換時間戳 時間戳轉換星期

時間戳轉換日期 string date orderinfo.getchangetime replace null dateformat sdf new dateformat mm dd string monthdate sdf.format new date long.parselong date ...