首页 > 数据库 >mysql中date_format函数格式化日期,如何精确到毫秒?

mysql中date_format函数格式化日期,如何精确到毫秒?

时间:2023-11-15 13:45:02浏览次数:39  
标签:week 00 .. format numeric mysql date where day

直接看官网文档 :

https://dev.mysql.com/doc/refman/8.0/en/date-and-time-functions.html#function_date-format

SpecifierDescription
%a Abbreviated weekday name (Sun..Sat)
%b Abbreviated month name (Jan..Dec)
%c Month, numeric (0..12)
%D Day of the month with English suffix (0th1st2nd3rd, …)
%d Day of the month, numeric (00..31)
%e Day of the month, numeric (0..31)
%f Microseconds (000000..999999)
%H Hour (00..23)
%h Hour (01..12)
%I Hour (01..12)
%i Minutes, numeric (00..59)
%j Day of year (001..366)
%k Hour (0..23)
%l Hour (1..12)
%M Month name (January..December)
%m Month, numeric (00..12)
%p AM or PM
%r Time, 12-hour (hh:mm:ss followed by AM or PM)
%S Seconds (00..59)
%s Seconds (00..59)
%T Time, 24-hour (hh:mm:ss)
%U Week (00..53), where Sunday is the first day of the week; WEEK() mode 0
%u Week (00..53), where Monday is the first day of the week; WEEK() mode 1
%V Week (01..53), where Sunday is the first day of the week; WEEK() mode 2; used with %X
%v Week (01..53), where Monday is the first day of the week; WEEK() mode 3; used with %x
%W Weekday name (Sunday..Saturday)
%w Day of the week (0=Sunday..6=Saturday)
%X Year for the week where Sunday is the first day of the week, numeric, four digits; used with %V
%x Year for the week, where Monday is the first day of the week, numeric, four digits; used with %v
%Y Year, numeric, four digits
%y Year, numeric (two digits)
%% A literal % character
%x x, for any “x” not listed above

里面有1个%f,但是是6位的,如果毫秒只需要3位,再套一层substring,效果如下:

 上图也顺便给了另1个小技巧:默认情况下now()和current_timestamp()函数,只精确到秒,如果需要到毫秒,传入3或6这样的精度值即可。

标签:week,00,..,format,numeric,mysql,date,where,day
From: https://www.cnblogs.com/yjmyzz/p/how_to_use_date_format_function_format_date_to_millisecon

相关文章

  • 随笔:Mysql增删改查
    id,name,age,sex,score增加两条数据:insertintotable_studentvalues(0,'name1',age1,'sex1',score1),(1,'name2',age2,'sex2',score2);将name1中的age1更新为age3:updatetable_studentsetage=age3whereid=0;删除name1的记录de......
  • MySQL Shell连接数据库报MySQL Error 1045 (28000)错误浅析
    这里简单总结一下mysqlshell访问数据库时报MySQLError1045(28000):Accessdeniedforuser'root'@'::1'(usingpassword:YES)的原因以及如何解决这个问题这里测试的环境为MySQL8.0.35,我们先来看看报错案例:$ mysqlsh -h localhost -P 7306 -u root -pPlease pr......
  • 记一次线上问题引发的对 Mysql 锁机制分析
    背景最近双十一开门红期间组内出现了一次因Mysql死锁导致的线上问题,当时从监控可以看到数据库活跃连接数飙升,导致应用层数据库连接池被打满,后续所有请求都因获取不到连接而失败整体业务代码精简逻辑如下:@Transactionpublicvoidservice(Integerid){delete(id);......
  • 记一次线上问题引发的对 Mysql 锁机制分析 | 京东物流技术团队
    背景最近双十一开门红期间组内出现了一次因Mysql死锁导致的线上问题,当时从监控可以看到数据库活跃连接数飙升,导致应用层数据库连接池被打满,后续所有请求都因获取不到连接而失败整体业务代码精简逻辑如下:@Transactionpublicvoidservice(Integerid){delete(id);inse......
  • mysql 操作详细教程
    MySQL是一种流行的关系型数据库管理系统,用于存储和管理数据。下面是MySQL操作的详细教程:安装MySQL:首先,你需要下载和安装MySQL。你可以从MySQL官方网站(https://www.mysql.com)上下载适合你操作系统的安装程序,并按照安装向导进行安装。启动MySQL服务器:安装完成后,你需要启动My......
  • 数据库性能查看-查看MySQL数据库操作记录
    测试orm或者Django序列化器的时候,我需要知道他们都干了什么,这就需要打开MySQL的操作日志进入MySQL的客户端命令界面:showvariableslike'gen%';+------------------+---------------------------------+|Variable_name|Value|+----------......
  • 为什么MySQL不建议使用delete删除数据?
    MySQL并不直接建议禁止使用DELETE语句删除数据,但是在某些情况下,使用DELETE可能会带来一些潜在的问题,特别是在大型数据库中。下面我将详细介绍为什么在某些情况下MySQL不建议过度使用DELETE语句来删除数据,并探讨其可能带来的影响。1.DELETE操作的影响DELETE语句用于从表中删除......
  • Mysql主键不要使用uuid或者不连续不重复雪花id
    一、简介     mysql官方推荐不要使用uuid或者不连续不重复的雪花id(long形且唯一,单机递增),而是推荐连续自增的主键id,官方的推荐是auto_increment,那么为什么不建议采用uuid,使用uuid究竟有什么坏处?二、对比    2.1、自增主键id         自增......
  • mysql跨库事务XA
    XA的性能很低,但是没得选的时候,也是个方案<?PHP$dbtest1=newmysqli("127.0.0.1","public","public","dbtest1")ordie("dbtest1连接失败");$dbtest2=newmysqli("127.0.0.1public","public","dbtest2&qu......
  • 实现批量插入和更新(mysql)
    在实际数据库应用中,经常需要实现插入或更新(插入新数据,如果已存在则更新已有数据)的功能。然而,在处理大量数据时,频繁的数据库I/O操作可能导致性能问题。MySQL批量插入和更新使用INSERT...ONDUPLICATEKEYUPDATEMySQL提供了INSERT...ONDUPLICATEKEYUPDATE语法,通......