当前位置:网站首页>Mysql根据时间搜索常用方法整理
Mysql根据时间搜索常用方法整理
2022-07-03 10:46:00 【追逐梦想永不停】
1.使用date_sub
查询3天内的数据
select * from mytable where update_time > date_sub(curdate(),interval 3 DAY)
此时,update_time为datetime、date、timestamp 等类型时,可以使用。
2.使用to_days
查询3天内的数据
select * from mytable where 3 > to_days(now())-to_days(update_time)
此时,update_time为datetime、date、timestamp 等类型时,可以使用。
3.时间转字符的方法,DATE_FORMAT
select DATE_FORMAT(update_time, '%Y-%m-%d %H:%i:%S') from mytable
4.字符转时间的方法,STR_TO_DATE
select str_to_date('2022/06/24','%Y/%m/%d');
5.字符转时间再转Timestamp的方法,UNIX_TIMESTAMP(不常用)
select UNIX_TIMESTAMP(str_to_date('2022/06/24','%Y/%m/%d'));
注意,这个方法不常用;如果想把datetime、date类型的数据查询出来、保存到timestamp列,只需要直接保存即可,无需转换;
如果想把字符类型的数据查询出来、保存到timestamp列,只需要转换为时间类型、然后保存即可,无需转换为timestamp;转换后反而会报错。(kettle数据抽取时发现的)
边栏推荐
- How to clean up v$rman_ backup_ job_ Details view reports error ora-02030
- 程序员的创业陷阱:接私活
- Solicitation for JGG special issue: spatio-temporal omics
- Gut | Yu Jun group of the Chinese University of Hong Kong revealed that smoking changes intestinal flora and promotes colorectal cancer (do not smoke)
- ASP. Net hotel management system
- Balance between picture performance of unity mobile game performance optimization spectrum and GPU pressure
- How to make others fear you
- Programmers' entrepreneurial trap: taking private jobs
- Intel 13th generation core flagship exposure, single core 5.5ghz
- 一文搞懂Go语言Context
猜你喜欢
![[OBS] configFile in ini format of OBS](/img/b2/0b130cee6ea884557a30e4b408f49e.png)
[OBS] configFile in ini format of OBS

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

This article explains the complex relationship between MCU, arm, MCU, DSP, FPGA and embedded system

Summary of interview questions (2) IO model, set, NiO principle, cache penetration, breakdown avalanche

ASP.NET-酒店管理系統

uniapp scroll view 解决高度自适应、弹框滚动穿透等问题。

00后抛弃互联网: 毕业不想进大厂,要去搞最潮Web3

Viewing binary bin files with notepad++ editor

Unique in the industry! Fada electronic contract is on the list of 36 krypton hard core technology enterprises

C language AES encryption and decryption
随机推荐
R language uses grid of gridextra package The array function combines multiple visual images of the lattice package horizontally, and the ncol parameter defines the number of columns of the combined g
软考中级软件设计师该怎么备考
R语言使用gridExtra包的grid.arrange函数将ggplot2包的多个可视化图像横向组合起来,ncol参数自定义组合图列数、nrow参数自定义组合图行数
How to become a senior digital IC Design Engineer (1-3) Verilog coding syntax: Verilog behavior level, register transfer level, gate level (abstract level)
机器学习 3.2 决策树模型 学习笔记(待补)
Spl06-007 air pressure sensor (example of barometer)
PHP基础
MATLAB extrait les données numériques d'un fichier txt irrégulier (simple et pratique)
Analysis of JMM memory model
Internet socket (non) blocking write/read n bytes
Key switch: press FN when pressing F1-F12
银泰百货点燃城市“夜经济”
(2) Base
动态规划(区间dp)
. \vmware-vdiskmanager. exe -k “c:\\xxxxx.vmdk”
Programmers' entrepreneurial trap: taking private jobs
DS90UB949
C语言二维数组
ORACLE进阶(一) 通过EXPDP IMPDP命令实现导dmp
Linear table sequence table comprehensive application problem p18