Home > Database > Mysql Tutorial > body text

MySQL-date time Extract function code example detailed introduction

黄舟
Release: 2017-03-13 13:18:01
Original
1454 people have browsed it

MySQLDate TimeExtractThe advantage of the function is that you can select various parts of the date and time, from the year all the way to microseconds. Let us use the MySQL date and time processing is easier.

MySQL date and time Extract (select) function.
1. Select various parts of 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
Copy after login

2. MySQL Extract() function can be implemented above 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
Copy after login

MySQL Extract() function has all the other functions except date() and time(). It also has functions such as selecting ‘day_microsecond’. Note that instead of just selecting day and microsecond, you select from the day part of the date all the way to the microsecond part.

The above is the detailed content of MySQL-date time Extract function code example detailed introduction. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template