当前位置:网站首页>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
边栏推荐
- delete和truncate
- opensips(1)——安装opensips详细流程
- 域内用户访问域外samba服务器用户名密码错误
- Get the value of state in effects in DVA
- sklearn之 Gaussian Processes
- Font shape `OMX/cmex/m/n‘ in size <10.53937> not available (Font) size <10.95> substituted.
- Solution record of slow access speed of SMB service in redhat6
- Pytorch学习记录(十一):数据增强、torchvision.transforms各函数讲解
- EditorConfig
- 线代第四章-向量组的线性相关
猜你喜欢
SQL注入
数字图像处理基础(冈萨雷斯)一
框架解析1.系统架构简介
你不能访问此共享文件夹,因为你组织的安全策略阻止未经身份验证的来宾访问
Pyqy5 learning (2): qmainwindow + QWidget + qlabel
MySQL lock mechanism
自动控制(韩敏版)
Pytorch学习记录(十):数据预处理+Batch Normalization批处理(BN)
Manually delete registered services on Eureka
Pytorch learning record (7): skills in processing data and training models
随机推荐
umi官网yarn create @umijs/umi-app 报错:文件名、目录名或卷标语法不正确
Latex快速入门
治療TensorFlow後遺症——簡單例子記錄torch.utils.data.dataset.Dataset重寫時的圖片維度問題
PyTorch入门小笔记——利用简单例子观察前向传播各个层输出的size
Pytorch學習記錄(十三):循環神經網絡((Recurrent Neural Network)
Configure domestic image accelerator for yarn
Pytoch learning record (x): data preprocessing + batch normalization (BN)
创建企业邮箱账户命令
Get the value of state in effects in DVA
Ptorch learning record (XIII): recurrent neural network
数字图像处理基础(冈萨雷斯)一
Ora: 28547 connection to server failed probable Oracle net admin error
线代第四章-向量组的线性相关
MySQL triggers, stored procedures, stored functions
图像恢复论文——[RED-Net, NIPS16]Image Restoration Using Very Deep Convolutional Encoder-Decoder Networks wi
Postfix变成垃圾邮件中转站后的补救
编程记录——图片旋转函数scipy.ndimage.rotate()的简单使用和效果观察
Conda 虚拟环境管理(创建、删除、克隆、重命名、导出和导入)
图像恢复论文简记——Uformer: A General U-Shaped Transformer for Image Restoration
io. lettuce. core. RedisCommandExecutionException: ERR wrong number of arguments for ‘auth‘ command