当前位置:网站首页>Using datetime in MySQL
Using datetime in MySQL
2022-06-12 04:19:00 【allway2】
MySQL Date time tutorial
MySQL Date and time type
DATETIME | YYYY-MM-DD HH:MM:SS |
DATE | YYYY-MM-DD |
TIMESTAMP | YYYYMMDDHHSSMM |
TIME | HH:MM:SS |
YEAR | YYYY |
MySQL Date time
CREATE TABLE vatsa(Dt DATETIME);
Now? , Insert data in the correct format , As shown below .
INSERT INTO vatsa(Dt) VALUES('2020-09-14 23:18:17');
note :
INSERT INTO vatsa(Dt) VALUES('2020=09=14 23*18*21');
But even though I'm sure they exist , But I didn't find a good reason to use it , So I suggest you abide by the agreement , Unless absolutely necessary .
SELECT * FROM vatsa;

Simple date and time calculations
DATETIME value , Use the function shown in the following statement :SELECT YEAR('2020-09-14 23:18:17') AS Year,
Month('2020-09-14 23:18:17') AS Month,
Day('2020-09-14 23:18:17') AS Day,
Hour('2020-09-14 23:18:17') AS Hour,
Minute('2020-09-14 23:18:17') AS Minute,
Second('2020-09-14 23:18:17') AS Second,
Date('2020-09-14 23:18:17') AS Date,
Time('2020-09-14 23:18:17') AS Time,
Quarter('2020-09-14 23:18:17') AS Quarter; 
SET @vatsaDATETIME = NOW();
SELECT YEAR(@vatsaDATETIME) AS Year,
Month(@vatsaDATETIME) AS Month,
Day(@vatsaDATETIME) AS Day,
Hour(@vatsaDATETIME) AS Hour,
Minute(@vatsaDATETIME) AS Minute,
Second(@vatsaDATETIME) AS Second,
Date(@vatsaDATETIME) AS Date,
Time(@vatsaDATETIME) AS Time,
Quarter(@vatsaDATETIME) AS Quarter; 
Basic arithmetic operation of date function
SET @vatsa = now();
SELECT @vatsa + 5; 2) To find out what the last five years were , Please use .
SET @vatsa = now();
SELECT @vatsa – 5; Now? , Let's discuss a basic real-time example .
SET @vatsa = now();
SELECT @vatsa - 5 AS PAST,
year(@vatsa) AS CURRENT,
@vatsa + 5 AS FUTURE; 
NOW() function
SELECT NOW();

CURRENT_DATE() function
SELECT CURRENT_DATE();

MySQL Date time and timestamp
TIMESTAMP(14) | YYYYMMDDHHMMSS |
TIMESTAMP(12) | YYMMDDHHMMSS |
TIMESTAMP(10) | YYMMDDHHMM |
TIMESTAMP(8) | YYYYMMDD |
TIMESTAMP(6) | YYMMDD |
TIMESTAMP(4) | YYMM |
TIMESTAMP(2) | YY |
Conclusion
边栏推荐
- Cryptology Summary
- Is it safe for Guojin Securities Commission Jinbao to open an account? How should we choose securities companies?
- 19. Optimized database query of tornado project
- 疫情数据分析平台工作报告【3】网站部署
- Solution en cas de défaillance du script Unity
- Smart panel WiFi linkage technology, esp32 wireless chip module, Internet of things WiFi communication application
- [FPGA chaos] implementation of FPGA based chaotic system Verilog
- Concept and introduction of microservice
- 成功解决:WARNING: There was an error checking the latest version of pip.
- Dynamic gauge (15) - Minimum toll
猜你喜欢

路灯照明物联网技术方案,ESP32-S3芯片通信应用,智能WiFi远程控制
![[C language] encapsulation interface (addition, subtraction, multiplication and division)](/img/8f/1351826a6f7e83ce90d32d7615adc1.png)
[C language] encapsulation interface (addition, subtraction, multiplication and division)

E-commerce middle office system architecture

疫情数据分析平台工作报告【2】接口API

Concept and introduction of microservice

疫情数据分析平台工作报告【6】可视化绘图

Naive Bayes classification of scikit learn
![[automation] generate xlsx report based on openstack automated patrol deployed by kolla](/img/65/f062a6a1080c42857466f13e67fef1.jpg)
[automation] generate xlsx report based on openstack automated patrol deployed by kolla

Smart panel WiFi linkage technology, esp32 wireless chip module, Internet of things WiFi communication application

【FPGA混沌】基于FPGA的混沌系统verilog实现
随机推荐
SQL Safe Backup显示器和缩放字体的支持
What does hard work mean to you?
疫情数据分析平台工作报告【8.5】额外的爬虫和绘图
请用递归的方法计算下列函数的值:px(x,n)=x-x^2 +x^3- x^4+… ((-1)n-1)(xn) n>0 **输入格式要求:“%lf%d“ 提示信息:“Enter X and N:”
Centernet2 practice: take you through the training of custom datasets with centernet2
[fpga+fft] design and implementation of FFT frequency meter based on FPGA
Construction case of Expressway Precast Beam Yard (with scheme text)
Will subsequent versions support code block search highlighting
[SC] OpenService FAILED 5: Access is denied.
智能面板WiFi聯動技術,ESP32無線芯片模組,物聯網WiFi通信應用
疫情数据分析平台工作报告【6】可视化绘图
Kotlin starts the process, the difference between launch and async, and starts the process in sequence
Function realization and application of trait
R语言write函数:使用write函数将数据写入RStudio控制台、write函数将数据写入新的Rstudio窗口(启动新的窗口)
无线物联网WiFi模块方案,ESP32-S3芯片技术,助力设备智能化
双目标定学习资料整理
windows如何安装多个版本mysql,如何同时启动
Work report of epidemic data analysis platform [1] data collection
基于SSH实现健身俱乐部管理系统
[C language] analysis of variable essence