MySQL Time Parts
Keep a time-of-day value separate from a calendar date and a long elapsed duration.
How it works
TIME can extract the time portion of a datetime-like value, while HOUR, MINUTE, SECOND and MICROSECOND expose fields. MySQL TIME can also represent durations outside an ordinary clock-day range, so do not assume every TIME value is a valid appointment time. The examples use a fixed timestamp and fractional seconds to make the precision visible. TIMESTAMP here is the function that combines date and time, not a column-definition discussion.
Choose the function from its contract
- TIME: Extracts the clock portion.
- HOUR: Reads the hour field.
- MINUTE: Reads the minute field.
- SECOND: Reads whole seconds.
- MICROSECOND: Reads fractional microseconds.
- TIMESTAMP: Combines date and time inputs.
Run in a disposable MySQL lab
Use Oracle MySQL 8.4 with InnoDB, not Bhylu’s SQLite playground. The examples were reviewed on MySQL 8.4.8. XAMPP may provide MariaDB, which has different feature and collation behaviour. Check your actual server before running the script. These lessons do not require a change to Bhylu’s PHP, Apache or normal database service.
- On a separate lab instance, create the empty bhylu_mysql_lab schema. Stop if it already exists; do not overwrite an existing database.
- Select that schema and import the complete repair-parts seed once. It sets the documented session mode, utf8mb4 collation, UTC and English date-name locale.
- Run this lesson in a fresh copy of the seed, not after another lesson’s writes. Use the command-line client or a compatible editor. DELIMITER lines are client instructions for stored-program examples.
Download this complete lesson script. Its setup is the linked seed; review the dataset before changing it. Administrative and destructive examples are restricted to the specifically named disposable objects. Every script repeats the session settings because each new connection has its own session. No MySQL browser runner is currently available.
Example
SET NAMES utf8mb4 COLLATE utf8mb4_0900_ai_ci;
SET SESSION sql_mode = 'STRICT_TRANS_TABLES,ONLY_FULL_GROUP_BY,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION';
SET SESSION time_zone = '+00:00';
SET SESSION lc_time_names = 'en_US';
SELECT 'TIME' AS operation, TIME('2026-02-14 10:30:45') AS result;
SELECT 'HOUR' AS operation, HOUR('10:30:45') AS result;
SELECT 'MINUTE' AS operation, MINUTE('10:30:45') AS result;
SELECT 'SECOND' AS operation, SECOND('10:30:45') AS result;
SELECT 'MICROSECOND' AS operation, MICROSECOND('10:30:45.123456') AS result;
SELECT 'TIMESTAMP' AS operation, TIMESTAMP('2026-02-14','01:02:03') AS result;
Expected result
TIME | 10:30:45 HOUR | 10 MINUTE | 30 SECOND | 45 MICROSECOND | 123456 TIMESTAMP | 2026-02-14 01:02:03
Choose column precision deliberately when fractional seconds matter; extracting microseconds cannot restore precision that was never stored. Avoid using display strings as the authoritative representation for cross-timezone events. A separate date and time may describe a local appointment, while an instant needs a clear conversion policy and origin timezone.
Use the official MySQL 8.4 reference for statement contracts and version details.