当前位置:网站首页>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 )
边栏推荐
- VPP three-layer network interconnection configuration
- Stm32hal library upgrades firmware based on flash analog U disk (detailed explanation)
- Xml的(DTD,xml解析,xml建模)
- Web security summary
- DNS多点部署IP Anycast+BGP实战分析
- 同事写了一个责任链模式,bug无数...
- ORACLE进阶(一) 通过EXPDP IMPDP命令实现导dmp
- How to become a senior digital IC Design Engineer (1-3) Verilog coding syntax: Verilog behavior level, register transfer level, gate level (abstract level)
- Programmers' entrepreneurial trap: taking private jobs
- 软考中级软件设计师该怎么备考
猜你喜欢
Hongmeng fourth training
Web安全总结
Processes and threads
解决msvcp120d.dll和msvcr120d.dll缺失
Redis things
【学习笔记】dp 状态与转移
Mmc5603nj geomagnetic sensor (Compass example)
基于turtlebot3实现SLAM建图及自主导航仿真
Cuiyusong, CTO of youzan: the core goal of Jarvis is to make products smarter and more reliable
After watching the video, AI model learned to play my world: cutting trees, making boxes, making stone picks, everything is good
随机推荐
Linear table sequence table comprehensive application problem p18
Uniapp implementation Click to load more
P3250 [HNOI2016] 网络 + [NECPC2022] F.Tree Path 树剖+线段树维护堆
Go语言实现静态服务器
STL教程9-容器元素深拷贝和浅拷贝问题
PHP基础
JGG专刊征稿:时空组学
如何将数字字符串转换为整数
rxjs Observable filter Operator 的实现原理介绍
The R language uses the hist function in the native package (basic import package, graphics) to visualize the histogram plot
[OBS] configFile in ini format of OBS
R语言使用gridExtra包的grid.arrange函数将lattice包的多个可视化图像横向组合起来,ncol参数自定义组合图列数、nrow参数自定义组合图行数
Software testing weekly (issue 78): the more confident you are about the future, the more patient you are about the present.
DNS多点部署IP Anycast+BGP实战分析
Application of high-precision indoor positioning technology in safety management of smart factory
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
导师对帮助研究生顺利完成学业提出了20条劝告:第一,不要有度假休息的打算.....
MySQL union和union all区别
C language utf8toutf16 (UTF-8 characters are converted to hexadecimal encoding)
Stm32hal library upgrades firmware based on flash analog U disk (detailed explanation)