| 일 | 월 | 화 | 수 | 목 | 금 | 토 |
|---|---|---|---|---|---|---|
| 1 | 2 | 3 | 4 | 5 | 6 | |
| 7 | 8 | 9 | 10 | 11 | 12 | 13 |
| 14 | 15 | 16 | 17 | 18 | 19 | 20 |
| 21 | 22 | 23 | 24 | 25 | 26 | 27 |
| 28 | 29 | 30 | 31 |
- Deep Learning
- Python
- 반복문
- 알고리즘
- 문자열
- 티스토리챌린지
- OOP
- Pre-processing
- 포인터
- Data Science
- pointer
- Class
- baekjoon
- programming
- 백준
- 배열
- function
- 오블완
- Object Oriented Programming
- array
- predictive analysis
- vscode
- 파이썬
- pass by reference
- assignment operator
- raw data
- const
- C++
- 함수
- string
- Today
- Total
Channi Studies
[MySQL] Day 5. CURRENT_DATE() & CURRENT_TIME() 본문
Let's starty by creating a temporary database for this post.
CREATE DATABASE test(
my_date DATE,
my_time TIME,
my_datetime DATETIME
);
SELECT * from test;

To get current date, time, or date time, there are 3 built-in functions, CURRENT_DATE(), CURRENT_TIME, and NOW()
Let's try inserting a new row of appropriate data obtained by these functions.
INSERT INTO test
VALUES (CURRENT_DATE(), CURRENT_TIME, NOW());
SELECT * FROM test;

When we add or subtract an integer from DATE, than it will change the date accordingly.
Same for TIME and DATETIME, each integer added or subtracted will change the time in seconds.
However, the date and time does not automatically updates when it's over the maximum dates in the month or over 60 seconds.
Any attempt of adding an invalid time or date will result in an error. (ex. 2021-21-42, 2025-03-40, 30:01:21, 01:82: 99, 3000-01-32 29:92:02)
For DATE, you have to add 100 for + 1 month, and add 10000 for + 1 year.
For TIME and DATETIME, you have to add 100 for +1 minute, add 10000 for +1 hour.
'SQL' 카테고리의 다른 글
| [MySQL] Day 7. CHECK Constraint (0) | 2025.04.02 |
|---|---|
| [MySQL] Day 6. UNIQUE & Not Null Constraint (0) | 2025.04.01 |
| [MySQL] Day 4. AUTOCOMMIT, COMMIT, ROLLBACK (0) | 2025.03.26 |
| [MySQL] Day 3. Update and Delete (0) | 2025.03.25 |
| [SQL] Day 2: INSERT INTO & SELECT WHERE (0) | 2025.03.15 |