- 日期转换函数的详细使用说明
-
Formats the
date
value according to theformat
string.The following specifiers may be used in the
format
string. The “%
” character is required before format specifier characters.Specifier Description %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 ( 0th
,1st
,2nd
,3rd
, …)%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
orPM
%r
Time, 12-hour ( hh:mm:ss
followed byAM
orPM
)%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 aboveRanges for the month and day specifiers begin with zero due to the fact that MySQL permits the storing of incomplete dates such as
'2014-00-00'
.The language used for day and month names and abbreviations is controlled by the value of the
lc_time_names
system variable (Section 10.7, “MySQL Server Locale Support”).For the
%U
,%u
,%V
, and%v
specifiers, see the description of theWEEK()
function for information about the mode values. The mode affects how week numbering occurs.DATE_FORMAT()
returns a string with a character set and collation given bycharacter_set_connection
andcollation_connection
so that it can return month and weekday names containing non-ASCII characters.mysql>
SELECT DATE_FORMAT('2009-10-04 22:23:00', '%W %M %Y');
-> 'Sunday October 2009' mysql>SELECT DATE_FORMAT('2007-10-04 22:23:00', '%H:%i:%s');
-> '22:23:00' mysql>SELECT DATE_FORMAT('1900-10-04 22:23:00',
->'%D %y %a %d %m %b %j');
-> '4th 00 Thu 04 10 Oct 277' mysql>SELECT DATE_FORMAT('1997-10-04 22:23:00',
->'%H %k %I %r %T %S %w');
-> '22 22 10 10:23:00 PM 22:23:00 00 6' mysql>SELECT DATE_FORMAT('1999-01-01', '%X %V');
-> '1998 52' mysql>SELECT DATE_FORMAT('2006-06-00', '%d');
-> '00'
- 浏览: 771042 次
- 性别:
- 来自: 广州
文章分类
最新评论
发表评论
-
mysql修改表、字段、库的字符集
2016-12-06 15:59 3180mysql修改表、字段、库的字符集(转) 原文链接:http ... -
用SQL命令查看Mysql数据库,表的大小方法
2016-05-07 22:42 1397要想知道每个数据库 ... -
mysql碎片整理方法
2015-11-10 11:55 5147对于一个表如果经常插入数据和删除数据,则会产生很多不连 ... -
mysql int(10)中的10表示的真正含义
2015-10-10 10:26 8190int(10): 之前总以为其中的10表示字段所能表示的位数 ... -
mysql replace into 用法详解
2015-10-10 09:53 5000Replace into是Insert into的增强版。在 ... -
mysql查看锁表方法详解
2015-10-17 16:51 22477mysql查看锁表方法详解 1、show OPEN ... -
mysql 修改表的语法详解
2015-07-21 20:09 1363mysql 修改表的详细语法介绍 ALTER [IG ... -
msyql设置密码报错:ERROR 1372 (HY000): 解决方法详解
2015-07-12 22:50 7390MySql给用户设置权限同时指定访问密码时,会提示如下错误 ... -
Linux系统上安装MySQL
2015-06-10 14:25 16491.准备工作 从MySQL官网上分别下载mysql服 ... -
mysql 在linux客户端插入数据中文乱码
2015-04-20 19:19 11641、查看系统客户端,数据库,连接层的编码 查看方法: h ... -
mysql 取每组前几条记录
2015-03-16 14:45 5214一、对分组的记录取前N条记录:例如:取每组的前3条最大的记 ... -
mysql数据导入、导出方法汇总
2015-03-06 11:20 3922一、mysql远程导入 前言部分 由于公司的MyS ... -
安装mysql
2015-03-04 10:04 417安装mysql (1)删除linux上已经安装的my ... -
mysql导入数据load data infile用法
2015-02-06 09:30 1237我们常常导入数据!mysql有一个高效导入方法,那就是load ... -
mysql导出数据不输出标题行
2015-01-14 09:49 4072当想使用数据库中的某些数据,想将其导入到文件中,而想去掉第一行 ... -
mysql导入导出数据中文乱码问题
2015-01-12 13:37 5464解决mysql导入导出数据乱码问题方法: 1、进入mysql ... -
select into outfile access deny问题
2015-01-12 11:49 3330本文转自:http://hatemysql.com/2010/ ... -
mysqldump导出时出现when doing LOCK TABLES
2015-01-12 11:25 2475执行 mysqldump -uxxx -pxxx -hxx ... -
CASE WHEN 用法介绍
2014-12-26 10:00 1057CASE WHEN 用法介绍 1. CASE WHEN 表达 ... -
sql 行列转换
2014-12-26 09:54 3112行转列的思想是通过case when 来实现 列转行的思想是通 ...
相关推荐
用 DATE_FORMAT 来格式化日期字段 SELECT DATE_FORMAT(crt_time,'%Y-%m-%d') FROM ad_n_advertise_t 您可能感兴趣的文章:MySQL中日期比较时遇到的编码问题解决办法PHP以及MYSQL日期比较方法mysql 获取当前日期函数...
本文转自:http://dev.mysql.com/doc/refman/4.1/en/date-and-time-functions.html#function_date-format DATE_FORMAT(date,format) Formats the date value according to the format string. The following ...
MySQL 获取当前日期及日期格式 获取系统日期: NOW() ...根据format字符串格式化date值: %S, %s 两位数字形式的秒( 00,01, …, 59) %I, %i 两位数字形式的分( 00,01, …, 59) %H 两位数字形式的小时,24 小时
动力节点的杜老师讲述的mysql教程,详细讲解了MySQL的相关知识,包括MySQL概述,MySQL应用环境,MySQL系统特性,MySQL初学基础,MySQL管理工具,如何安装MySQL及MySQL新特性,通过观看可掌握MySQL全套知识。
我们在写SQL时候,往往会需要格式化或多表联合查询,现在来一个实例看看这个问题 SELECT t.id, t.topic_title AS title, IF(sch.is_true='1','答案正确','答案错误') as answer, DATE_FORMAT(sch.create_time, '%Y-%...
mysql日期函数From_unixtime及UNIX_TIMESTAMP及DATE_FORMAT(后者只能格式化标准日期格式,时间戳的不行)
1. DATE_FORMAT() 函数用于以不同的格式显示日期/时间数据。 DATE_FORMAT(date,format) format参数的格式有 %a 缩写星期名 %b 缩写月名 %c 月,数值 %D 带有英文前缀的月中的天 %d 月的天,数值(00-31)...
本文实例讲述了thinkphp5.1框架实现格式化mysql时间戳为日期的方式。分享给大家供大家参考,具体如下: 方式一 使用mysql函数FROM_UNIXTIME(unix_timestamp,format)直接转换 select FROM_UNIXTIME(o.create_time,'...
1.我的MySQL中的start_time存储的是2018-03-21 10:55:32格式的时间,我需要按照YYYY-MM-DD格式来查询,我的MySQL中的sql是这样写的: SELECT * from mytable WHERE DATE_FORMAT(start_time,”%Y-%m-%d”)=’2018-03...
MYSQL 获取当前日期及日期格式 ...根据format字符串格式化date值: %S, %s 两位数字形式的秒( 00,01, …, 59) %I, %i 两位数字形式的分( 00,01, …, 59) %H 两位数字形式的小时,24 小时(00,01, …, 23)
date_format(date, format) 函数,MySQL日期格式化函数date_format() unix_timestamp() 函数 str_to_date(str, format) 函数 from_unixtime(unix_timestamp, format) 函数,MySQL时间戳格式化函
函数:FROM_UNIXTIME...根据format字符串格式化date值。下列修饰符可以被用在format字符串中: %M 月名字(January……December)%W 星期名字(Sunday……Saturday)%D 有英语前缀的月份的日期(1st, 2nd, 3rd, 等等。)%
总结的MySQL format格式化的格式('%Y-%m-%d %H:%i:%s'),可用于MySQL格式化函数(FROM_UNIXTIME(timestamp,format)、DATE_FORMAT(date, format)等。)
可用DATE_FORMAT( ) 来格式化DATE 或DATETIME 值,以便得到所希望的格式。根据format字符串格式化date值: %S, %s 两位数字形式的秒( 00,01, . . ., 59) %i 两位数字形式的分( 00,01, . . ., 59) %H 两位数字...
mysql的日期和时间函数 这里是一个使用日期函数的例子。下面的查询选择所有 date_col 值在最后 30 天内的记录。 mysql> SELECT something FROM tbl_name WHERE TO_DAYS(NOW()) - TO_DAYS(date_col) ...
日期格式化函数: DATE_FORMAT:时间格式化为字符串; STR_TO_DATE:时间字符串转为为日期格式; 日期加减函数: DATE_SUB:日期做减法 DATE_ADD:日期做加法
代码如下: select * from table where DATE_FORMAT(FROM_UNIX...timestamp,format)是MySQL里的时间函数 ,unix_timestamp可以是字段名,也可以直接是Unix时间,format主要是将返回值格式化。 若format已经给出,则结果的
根据format字符串格式化date值。下列修饰符可以被用在format字符串中: %M 月名字(January……December) %W 星期名字(Sunday……Saturday) %D 有英语前缀的月份的日期(1st, 2nd, 3rd, 等等。) %Y 年...
MySQL常用命令 日期 / 时间函数 -- 当前日期时间 select now() select sysdate() select current_timestamp() -- 当前日期 select current_date()...-- 格式化时间 select date_format('yyyy-mm-dd hh:ii:ss', '%d