Summary of time date and conversion functions commonly used in Mysql

  • 2021-10-25 00:00:39
  • OfStack

This paper mainly summarizes some commonly used mysql time and date and conversion functions in practical application

1. now (): Returns the current date and time


select now();
//2018-04-21 09:19:21 

2. curdate (): Returns the current date


select curdate();
//2018-04-21

3. dayofweek (data): What day of the week is the return date data


 ( 1 =  On Sunday, 2 = Week 1...7= Week 6,ODBC Standard) 
select dayofweek( ' 2018-02-13'); 
// 3

4. weekday (date): What day of the week is the return date data


 ( 0 =  On Sunday, 1 = Week 1...6= Week 6,ODBC Standard) 
select WEEKDAY('1997-10-04 22:23:00');
//5 

5. dayofmonth (date): Returns date is the day of the month (range 1-31)


select dayofmonth('2018-04-21');
//21 

6. dayofyear (date): Returns the day ordinal of the year that date is (range 1-366)


select dayofyear('2018-01-01');
//1 

7. month (date): Returns the month value in date


select month('2018-04-21');
//4

8. dayname (date): Returns the day of the week for date (English name returns)


select dayname('1998-02-05');
//Thursday

9. monthname (date): What month is returned to date


select monthname('2018-02-01')
//February

10. quarter (date): Returns which quarter of the year date is


select quarter('2018-04-21');
//2 

11. week (date, first): What week of year is date returned


select curdate();
//2018-04-21
0

12. year (date): Returns the year in date (range 1000-9999)


select curdate();
//2018-04-21
1

Summarize


Related articles: