The MySQL Date and Time Extract function has the advantage of selecting various parts of the date and time, from year to microsecond, making it easier to process MySQL date and time.
MySQL Date and Time Extract selection) function.
1. Select each part of the date and time: date, time, year, quarter, month, day, hour, minute, second, microsecond
- set @dt = '2008-09-10 07:15:30.123456';
- select date(@dt); -- 2008-09-10
- select time(@dt); -- 07:15:30.123456
- select year(@dt); -- 2008
- select quarter(@dt); -- 3
- select month(@dt); -- 9
- select week(@dt); -- 36
- select day(@dt); -- 10
- select hour(@dt); -- 7
- select minute(@dt); -- 15
- select second(@dt); -- 30
- select microsecond(@dt); -- 123456
2. MySQL Extract () function, which can implement similar functions:
- set @dt = '2008-09-10 07:15:30.123456';
- select extract(year from @dt); -- 2008
- select extract(quarter from @dt); -- 3
- select extract(month from @dt); -- 9
- select extract(week from @dt); -- 36
- select extract(day from @dt); -- 10
- select extract(hour from @dt); -- 7
- select extract(minute from @dt); -- 15
- select extract(second from @dt); -- 30
- select extract(microsecond from @dt); -- 123456
-
- select extract(year_month from @dt); -- 200809
- select extract(day_hour from @dt); -- 1007
- select extract(day_minute from @dt); -- 100715
- select extract(day_second from @dt); -- 10071530
- select extract(day_microsecond from @dt); -- 10071530123456
- select extract(hour_minute from @dt); -- 715
- select extract(hour_second from @dt); -- 71530
- select extract(hour_microsecond from @dt); -- 71530123456
- select extract(minute_second from @dt); -- 1530
- select extract(minute_microsecond from @dt); -- 1530123456
- select extract(second_microsecond from @dt); -- 30123456
In addition to date () and time () functions, the MySQL Extract () function must be fully functional. You can also select 'day _ microsecond. Note that we will not only select day and microsecond, but choose from day of the date to microsecond.
MySQL date functions
Provides you with an in-depth understanding of the MYSQL Cast function.
MySQL string segmentation and concatenation statements
View MySQL Default Character Set
Role of MySQL Foreign keys in Databases