加入收藏 | 设为首页 | 会员中心 | 我要投稿 拼字网 - 核心网 (https://www.hexinwang.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 站长学院 > MySql教程 > 正文

MySQL第三课 函数以及时间相关问题

发布时间:2022-07-09 22:19:52 所属栏目:MySql教程 来源:互联网
导读:MySQL第三课 函数以及时间相关问题: 1)删除某一个时间之前的记录 delete from cs_storage_video_file where date(start_time) = 2017-10-27 问题,目前只是支持精确到日,无法支持时分秒,如下指令删除异常 delete from cs_storage_video_file where date(s
       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’
 
  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_time

(编辑:拼字网 - 核心网)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!