Reputation: 67
I've discovered that function YEAR(CURRENT_TIME())
returns an 2023 year instead of NULL as I thought or something like that.
When i made this query
SELECT DAY(CURRENT_TIME()), MONTH(CURRENT_TIME()), YEAR(CURRENT_TIME());
I got the next result
+---------------------+-----------------------+----------------------+
| DAY(CURRENT_TIME()) | MONTH(CURRENT_TIME()) | YEAR(CURRENT_TIME()) |
+---------------------+-----------------------+----------------------+
| 24 | 11 | 2023 |
+---------------------+-----------------------+----------------------+
So why does 'TIME' implicitly stores the date?
Upvotes: -1
Views: 119
Reputation: 34231
The answer is that mysql performs an implicit time -> datetime conversion when you call the year() function on the returned time as year() cannot operate on time data type.
As mysql manual on date and time data types conversion says:
For conversion of TIME values to other temporal types, the value of CURRENT_DATE() is used for the date part.
Upvotes: 1