当前位置:网站首页>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 )
边栏推荐
- Spl06-007 air pressure sensor (example of barometer)
- C语言 AES加解密
- Unity3D学习笔记5——创建子Mesh
- 软件测试周刊(第78期):你对未来越有信心,你对现在越有耐心。
- 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
- 简单工厂和工厂方法模式
- phpcms 提示信息頁面跳轉showmessage
- 一文搞懂Go语言Context
- How to make others fear you
- 2022年中南大学夏令营面试经验
猜你喜欢
【学习笔记】dp 状态与转移
Unity3D学习笔记5——创建子Mesh
Abandon the Internet after 00: don't want to enter a big factory after graduation, but go to the most fashionable Web3
FL Studio 20 unlimited trial fruit arranger Download
Excel表格转到Word中,表格不超边缘纸张范围
After using the thread pool for so long, do you really know how to reasonably configure the number of threads?
2022年湖南工学院ACM集训第二次周测题解
ftp登录时,报错“530 Login incorrect.Login failed”
ASP. Net hotel management system
Numpy np. Max and np Maximum implements the relu function
随机推荐
Stm32hal library upgrades firmware based on flash analog U disk (detailed explanation)
外插散点数据
After watching the video, AI model learned to play my world: cutting trees, making boxes, making stone picks, everything is good
Web security summary
Unity3D学习笔记5——创建子Mesh
libvirt 中体验容器
Solicitation for JGG special issue: spatio-temporal omics
简单工厂和工厂方法模式
How to become a senior digital IC Design Engineer (1-5) Verilog coding syntax: operand
How to become a senior digital IC Design Engineer (1-2) Verilog coding syntax: Verilog 1995, 2001, 2005 standards
机器学习 3.2 决策树模型 学习笔记(待补)
Technical experts from large factories: how can engineers improve their communication skills?
同事写了一个责任链模式,bug无数...
Cuiyusong, CTO of youzan: the core goal of Jarvis is to make products smarter and more reliable
(database authorization - redis) summary of unauthorized access vulnerabilities in redis
一些常用术语
Mysql根据时间搜索常用方法整理
How to become a senior digital IC Design Engineer (1-3) Verilog coding syntax: Verilog behavior level, register transfer level, gate level (abstract level)
.\vmware-vdiskmanager.exe -k “c:\\xxxxx.vmdk”
Some common terms