当前位置:网站首页>Viewer: introduce MySQL date function
Viewer: introduce MySQL date function
2022-04-23 05:57:00 【ShuangTwo】
interviewter: How to get the current date and time
select now();
select sysdate();
select current_timestamp;
select current_timestamp();
select localtime;
select localtime();
select localtimestamp;
select localtimestamp();
interviewter: If I just want to print the date , What to do with
select curdate();
select current_date;
select current_date();
select utc_date;
select utc_date();
interviewter: Now I don't want to check the date , I'd like to see the specific time
select curtime();
select current_time;
select current_time();
select utc_time;
select utc_time();
interviewter: Do you understand the conversion of date and time stamp
select from_unixtime(1649402591); -- take UNIX The time of the timestamp is converted to the time of the normal format
2022-04-08 15:23:11
select unix_timestamp("2022-04-08 15:23:11"); -- Time date With UNIX Return in the form of a timestamp
1649402591
-- These two methods are used for time stamp and date conversion
select unix_timestamp(); -- With UNIX Returns the current time in the form of a timestamp
1649402591
-- Brief notes unix_timestamp(), If there is a time parameter, it is converted to the corresponding timestamp , Get the current timestamp without parameters , The returned results are all time stamps
interviewter: What if I just want to get a certain part of the date and time
select now(); -- 2022-04-08 15:29:55
select year("2022-04-08 15:29:55");
select month("2022-04-08 15:29:55");
select day("2022-04-08 15:29:55");
select hour("2022-04-08 15:29:55");
select minute("2022-04-08 15:29:55");
select second("2022-04-08 15:29:55");
select dayname("2022-04-08 15:29:55"); -- Return the English name of the day of the week
select monthname("2022-04-08 15:29:55"); -- Return the English name of the month
select weekday("2022-04-08 15:29:55"); -- Zhou 1 yes 0, Zhou 2 yes 1...... Sunday is 6
select quarter("2022-04-08 15:29:55"); -- Returns the quarter corresponding to the date
-- Go back to the week of the year
select week("2022-04-08 15:29:55");
select weekofyear("2022-04-08 15:29:55");
select dayofyear("2022-04-08 15:29:55"); -- The return date is the day of the year
select dayofmonth("2022-04-08 15:29:55"); -- The return date is the day of the month
select dayofweek("2022-04-08 15:29:55"); -- What day of the week , Sunday is 1, Monday is 2...... Saturday is 7
-- 2022-04-08 15:29:55
select extract(year from "2022-04-08 15:29:55"); -- 2022
select extract(month from "2022-04-08 15:29:55"); -- 4
select extract(week from "2022-04-08 15:29:55"); -- 14
select extract(day from "2022-04-08 15:29:55"); -- 8
select extract(hour from "2022-04-08 15:29:55"); -- 15
select extract(minute from "2022-04-08 15:29:55"); -- 29
select extract(second from "2022-04-08 15:29:55"); -- 55
select extract(year_month from "2022-04-08 15:29:55"); -- 202204
select extract(day_hour from "2022-04-08 15:29:55"); -- 815
select extract(day_minute from "2022-04-08 15:29:55"); -- 81529
select extract(day_second from "2022-04-08 15:29:55"); -- 8152955
select extract(hour_minute from "2022-04-08 15:29:55"); -- 1529
select extract(hour_second from "2022-04-08 15:29:55"); -- 152955
select extract(minute_second from "2022-04-08 15:29:55"); -- 2955
interviewter: I want to know how many seconds there are in a certain time and how to convert , On the contrary
select time_to_sec("15:29:55")
select sec_to_time(55795);
interviewter: Will the date time interval method be used
-- Returns the difference between the given date and time INTERVAL Date time of the time period ( Up )
select date_add("2022-04-08 15:29:55", interval 1 year);
select date_add("2022-04-08 15:29:55", interval 1 month);
select date_add("2022-04-08 15:29:55", interval 1 day);
select date_add("2022-04-08 15:29:55", interval 1 hour);
select date_add("2022-04-08 15:29:55", interval 1 minute);
select date_add("2022-04-08 15:29:55", interval 1 second);
select adddate("2022-04-08 15:29:55", interval 2 year) -- The method and date_add equally
-- Returns the difference between the given date and time INTERVAL Date and time of the time interval ( Down )
select date_sub("2022-04-08 15:29:55", interval 1 year);
select date_sub("2022-04-08 15:29:55", interval 1 month);
select date_sub("2022-04-08 15:29:55", interval 1 day);
select date_sub("2022-04-08 15:29:55", interval 1 hour);
select date_sub("2022-04-08 15:29:55", interval 1 minute);
select date_sub("2022-04-08 15:29:55", interval 1 second);
select subdate("2022-04-08 15:29:55", interval 2 year) -- The method and date_sub equally
-- Short for :add Add ,sub reduce , The main difference between these two methods is to return the up time interval and the down time interval
select addtime("2022-04-08 15:29:55", 10); -- Returns the time after a given time plus how many seconds , Set the second parameter to seconds
select subtime("15:29:55", "15:20:00"); -- return time1 subtract time2 After time
select datediff("2022-04-08", "2022-04-01"); -- return date1 subtract date2 Later date
select timediff("15:29:55", "15:20:00"); -- return time1 subtract time2 Time interval of
select last_day("2022-04-08 15:29:55"); -- Returns the date of the last day of the month in which the given date time is located
select adddate("2022-04-08 15:29:55", 10); -- Returns the time after a given date plus the number of days , Set the second parameter
interviewter: How do dates and strings convert to each other
select date_format("20220408152955", '%Y-%m-%d'); -- Convert string to date
select time_format("20220408152955", '%H:%i:%s') -- Convert string to time
select str_to_date("2022-04-08 15:29:55", '%Y-%m-%d %H:%i:%s') -- Convert time string to date
| Format symbol | explain | Format symbol | explain |
|---|---|---|---|
| %Y | 4 The number of digits indicates the year | %y | Two digits for the year |
| %M | The name of the month means the month (January,…) | %m | Two figures indicate the month (01,02,03...) |
| %b | Abbreviated month name (Jan.,Feb.,…) | %c | The number represents the month (1,2,3,…) |
| %D | The English suffix indicates the number of days in the month (1st,2nd,3rd,…) | %d | Two figures indicate the number of days in the month (01,02…) |
| %e | The number of days in the month (1,2,3,4,5…) | ||
| %H | Two figures represent decimals ,24 hourly (01,02…) | %h and %I | Two figures represent hours ,12 hourly (01,02…) |
| %k | Hours in digital form ,24 hourly (1,2,3) | %l | The number represents the hour ,12 hourly (1,2,3,4…) |
| %i | Two figures represent minutes (00,01,02) | %S and %s | Two digits are seconds (00,01,02…) |
| %W | The name of the week of the week (Sunday…) | %a | The abbreviation of a week (Sun.,Mon.,Tues.,…) |
| %w | Number the days of the week (0=Sunday,1=Monday…) | ||
| %j | With 3 The number of digits represents the number of days in the year (001,002…) | %U | Number the week of the year ,(1,2,3..) among Sunday For the first day of the week |
| %u | Number the week of the year ,(1,2,3..) among Monday For the first day of the week | ||
| %T | 24 hourly | %r | 12 hourly |
| %p | AM or PM | %% | Express % |
版权声明
本文为[ShuangTwo]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204230541367764.html
边栏推荐
- 一文读懂当前常用的加密技术体系(对称、非对称、信息摘要、数字签名、数字证书、公钥体系)
- 容器
- Anaconda
- Opensips (1) -- detailed process of installing opensips
- 线性代数第三章-矩阵的初等变换与线性方程组
- MySql基础狂神说
- 对比学习论文——[MoCo,CVPR2020]Momentum Contrast for Unsupervised Visual Representation Learning
- 在Jupyter notebook中用matplotlib.pyplot出现服务器挂掉、崩溃的问题
- Remedy after postfix becomes a spam transit station
- JVM系列(3)——内存分配与回收策略
猜你喜欢

框架解析1.系统架构简介

你不能访问此共享文件夹,因为你组织的安全策略阻止未经身份验证的来宾访问

数字图像处理基础(冈萨雷斯)一
![图像恢复论文——[RED-Net, NIPS16]Image Restoration Using Very Deep Convolutional Encoder-Decoder Networks wi](/img/1b/4eea05e2634780f45b44273d2764e3.png)
图像恢复论文——[RED-Net, NIPS16]Image Restoration Using Very Deep Convolutional Encoder-Decoder Networks wi

图解numpy数组矩阵

手动删除eureka上已经注册的服务

Gaussian processes of sklearn

Conda 虚拟环境管理(创建、删除、克隆、重命名、导出和导入)

JVM family (4) -- memory overflow (OOM)

PyQy5学习(三):QLineEdit+QTextEdit
随机推荐
PyQy5学习(三):QLineEdit+QTextEdit
Latex快速入门
Use Matplotlib. In Jupiter notebook Pyplot server hangs up and crashes
JVM系列(3)——内存分配与回收策略
Pytorch学习记录(四):参数初始化
框架解析1.系统架构简介
Get the value of state in effects in DVA
filebrowser实现私有网盘
Font shape `OMX/cmex/m/n‘ in size <10.53937> not available (Font) size <10.95> substituted.
sklearn之 Gaussian Processes
mysql如何将存储的秒转换为日期
Graphic numpy array matrix
线程的底部实现原理—静态代理模式
Pytorch学习记录(十二):学习率衰减+正则化
Anaconda installed pyqt5 and pyqt5 tools without designer Exe problem solving
Getting started with JDBC \ getting a database connection \ using Preparedstatement
Shansi Valley P290 polymorphism exercise
Pytorch学习记录(九):Pytorch中卷积神经网络
PreparedStatement防止SQL注入
Pytorch learning record (7): skills in processing data and training models