当前位置:网站首页>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 )
边栏推荐
- The LINQ expression node type 'ArrayIndex' is not supported in LINQ to Entities
- After using the thread pool for so long, do you really know how to reasonably configure the number of threads?
- 抓包整理外篇fiddler———— 会话栏与过滤器[二]
- C language AES encryption and decryption
- STL教程9-容器元素深拷贝和浅拷贝问题
- 用了这么久线程池,你真的知道如何合理配置线程数吗?
- Technical experts from large factories: how can engineers improve their communication skills?
- 2022年中南大学夏令营面试经验
- Programmers' entrepreneurial trap: taking private jobs
- Uniapp implementation Click to load more
猜你喜欢

Processes and threads

2022年湖南工学院ACM集训第二次周测题解

Extrapolated scatter data

2022 northeast four provinces match VP record / supplementary questions

C language AES encryption and decryption

Use typora to draw flow chart, sequence diagram, sequence diagram, Gantt chart, etc. for detailed explanation

Driver development based on I2C protocol

The uniapp scroll view solves the problems of high adaptability and bullet frame rolling penetration.

836. 合并集合(DAY 63)并查集

Kibana~Kibana的安装和配置
随机推荐
Redis things
phpcms 提示信息页面跳转showmessage
STL教程8-map
机器学习 3.2 决策树模型 学习笔记(待补)
ASP.NET-酒店管理系统
How should intermediate software designers prepare for the soft test
金额计算用 BigDecimal 就万无一失了?看看这五个坑吧~~
Technical experts from large factories: how can engineers improve their communication skills?
typeScript
R语言使用aggregate函数计算dataframe数据分组聚合的均值(sum)、不设置na.rm计算的结果、如果分组中包含缺失值NA则计算结果也为NA
STL教程9-容器元素深拷贝和浅拷贝问题
Leetcode 46: full arrangement
Key switch: press FN when pressing F1-F12
PHP Basics
抓包整理外篇fiddler———— 会话栏与过滤器[二]
Slam mapping and autonomous navigation simulation based on turnlebot3
ASP. Net hotel management system
R language uses the aggregate function to calculate the mean value (sum) of dataframe data grouping aggregation without setting na The result of RM calculation. If the group contains the missing value
How to become a senior digital IC Design Engineer (1-3) Verilog coding syntax: Verilog behavior level, register transfer level, gate level (abstract level)
鸿蒙第四次培训