当前位置:网站首页>MySQL searches and sorts out common methods according to time
MySQL searches and sorts out common methods according to time
2022-07-03 11:43:00 【Never stop chasing dreams】
1. Use date_sub
Inquire about 3 Days of data
select * from mytable where update_time > date_sub(curdate(),interval 3 DAY)
here ,update_time
by datetime、date、timestamp
Equal type time , have access to .
2. Use to_days
Inquire about 3 Days of data
select * from mytable where 3 > to_days(now())-to_days(update_time)
here ,update_time
by datetime、date、timestamp
Equal type time , have access to .
3. The method of converting time into characters ,DATE_FORMAT
select DATE_FORMAT(update_time, '%Y-%m-%d %H:%i:%S') from mytable
4. The method of character to time ,STR_TO_DATE
select str_to_date('2022/06/24','%Y/%m/%d');
5. Character to time to turn Timestamp Methods ,UNIX_TIMESTAMP( Not commonly used )
select UNIX_TIMESTAMP(str_to_date('2022/06/24','%Y/%m/%d'));
Be careful , This method is not commonly used ; If you want to put the datetime、date Type of data can be found 、 Save to timestamp Column , Just save it directly , There is no need to convert ;
If you want to query the data of character type 、 Save to timestamp Column , Just convert to time type 、 And save it , There is no need to convert to timestamp; Errors will be reported after conversion .(kettle Found during data extraction )
边栏推荐
- Asyncio warning deprecationwarning: there is no current event loop
- Programmers' entrepreneurial trap: taking private jobs
- Excel快速跨表复制粘贴
- JGG专刊征稿:时空组学
- Solicitation for JGG special issue: spatio-temporal omics
- phpcms 提示信息页面跳转showmessage
- Numpy np. Max and np Maximum implements the relu function
- VS2015的下载地址和安装教程
- Leetcode 46: full arrangement
- R language uses grid of gridextra package The array function combines multiple visual images of the ggplot2 package horizontally, and the ncol parameter defines the number of columns of the combined g
猜你喜欢
Slam mapping and autonomous navigation simulation based on turnlebot3
Hongmeng fourth training
ASP. Net hotel management system
Understand go language context in one article
ftp登录时,报错“530 Login incorrect.Login failed”
Excel表格转到Word中,表格不超边缘纸张范围
2022 northeast four provinces match VP record / supplementary questions
rxjs Observable filter Operator 的实现原理介绍
Extrapolated scatter data
The uniapp scroll view solves the problems of high adaptability and bullet frame rolling penetration.
随机推荐
How should intermediate software designers prepare for the soft test
previous permutation lintcode51
(database authorization - redis) summary of unauthorized access vulnerabilities in redis
ORACLE进阶(一) 通过EXPDP IMPDP命令实现导dmp
Repo ~ common commands
鸿蒙第三次培训(项目实训)
The tutor put forward 20 pieces of advice to help graduate students successfully complete their studies: first, don't plan to take a vacation
R语言使用原生包(基础导入包、graphics)中的hist函数可视化直方图(histogram plot)
Excel快速跨表复制粘贴
Modular programming of single chip microcomputer
836. 合并集合(DAY 63)并查集
用了这么久线程池,你真的知道如何合理配置线程数吗?
Dynamic programming (interval DP)
phpcms 提示信息頁面跳轉showmessage
R语言使用gridExtra包的grid.arrange函数将ggplot2包的多个可视化图像横向组合起来,ncol参数自定义组合图列数、nrow参数自定义组合图行数
The excel table is transferred to word, and the table does not exceed the edge paper range
GCC compilation process and dynamic link library and static link library
解决msvcp120d.dll和msvcr120d.dll缺失
Understand go language context in one article
Application of high-precision indoor positioning technology in safety management of smart factory