MySQL第三課 函數以及時間相關問題

1)刪除某一個時間以前的記錄

delete from cs_storage_video_file where date(start_time) <= '2017-10-27'

問題,目前只是支持精確到日,沒法支持時分秒,以下指令刪除異常

delete from cs_storage_video_file where date(start_time) <= '2017-10-27 09:00:00'


2)uuid函數提供一個默認的id


3)now函數提供當前的時間,格式是datetime數據庫

例子服務器

update cs_fire_control_device set temperature = 23, time = now()   where id=‘123456789’ide


MySQL服務器版本 5.7.20,數據類型選擇datetime,長度和小數點設置沒法保存(經過NavCat工具訪問數據庫),都只能是零(MySQL版本決定),這個版本時間類型沒法精確到毫秒或者微妙函數

測試當前版本是否能夠精確到毫秒
CREATE TABLE `testmilisecond` (
`tab1_id` VARCHAR(11) DEFAULT NULL,
`create` TIMESTAMP(3) NULL DEFAULT NULL,
`create2` DATETIME(3) DEFAULT NULL
) ENGINE=INNODB DEFAULT CHARSET=utf8工具

SELECT * FROM testmilisecond;測試



4) 格式化datetime返回一個日期的字符串

date_format(cs_alarm_templet.start_time,'%Y-%m-%d %H:%i:%s') as szstart_time

5) 格式化time返回一個時分秒的字符串
1.    convert(cs_alarm_model_times.start_time, CHAR) as szstart_time
2.     convert(cs_alarm_model_times.start_time, BINARY) as szstart_time
3.    cast(cs_alarm_model_times.start_time AS CHAR) as szstart_timeui


6)格式化一個UNIX時間戳orm

select   FROM_UNIXTIME(1598862000)字符串

2020/8/31 16:20:00it

相關文章
相關標籤/搜索