일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
- array
- vscode
- 배열
- 함수
- OOP
- 오블완
- C++
- 알고리즘
- function
- assignment operator
- programming
- string
- Data Science
- 티스토리챌린지
- predictive analysis
- raw data
- pass by reference
- 포인터
- const
- 반복문
- 문자열
- Object Oriented Programming
- 백준
- Pre-processing
- Deep Learning
- 파이썬
- Python
- pointer
- baekjoon
- Class
- 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 |