The MINUTE() function in MySQL is used to extract the minute part from a time or datetime value. It returns the minute (a number from 0 to 59) of a given time or datetime expression.
Syntax:
MINUTE(time_or_datetime)
Parameters:
time_or_datetime: This is the time or datetime value from which you want to extract the minute.
Example 1: Extracting minutes from a TIME value
SELECT MINUTE('15:30:45');
Result:
30
Example 2: Extracting minutes from a DATETIME value
SELECT MINUTE('2024-12-23 12:45:30');
Result:
45
Example 3: Using MINUTE() with NOW()
SELECT MINUTE(NOW());
This will return the current minute from the current server time.
Example 4: Using MINUTE() in a WHERE clause
SELECT * FROM events WHERE MINUTE(event_time) = 15;
This query will return all events where the minute part of the event_time is 15.
Let me know if you'd like more examples or explanations!
No comments:
Post a Comment