Summary of commonly used time, date and conversion functions in Mysql

Summary of commonly used time, date and conversion functions in Mysql

This article mainly summarizes some commonly used MySQL time and date and conversion functions in practical applications

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) : Returns the day of the week of the date data

(1 = Sunday, 2 = Monday...7 = Saturday, ODBC standard)
select dayofweek('2018-02-13'); 
// 3

4.weekday(date) : Returns the day of the week of the date data

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

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

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

6.dayofyear(date) : Returns the day 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 (returns the English name)

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

9.monthname(date): Returns the month of date (in English)

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

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

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

11.week(date,first): Returns the first week of the year that date is

(Parameter first: 0 means Sunday is the beginning of the week, 1 means Monday is the beginning of the week, default is 0)
select week('2018-02-20'); // 7
select week('2018-02-20',0); //7
select week('2018-02-20',1); //8

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

select year('98-02-03');
//1998

Summarize

The above is a summary of the commonly used time, date and conversion functions in MySQL. I hope it will be helpful to you. If you have any questions, please leave me a message and I will reply to you in time. I would also like to thank everyone for their support of the 123WORDPRESS.COM website!

You may also be interested in:
  • Python MySQL datetime formatting as parameter operations
  • Example analysis of interval calculation of mysql date and time
  • Summary of how to format MySQL timestamp as date using thinkphp5.1 framework
  • Mysql optimization techniques for querying dates based on time
  • mysql gets yesterday's date, today's date, tomorrow's date, and the time of the previous hour and the next hour
  • Analyze the selection problem of storing time and date types in MySQL
  • MySQL gets the current date and time function
  • How to query date and time in mysql

<<:  Vue implements pull-down to load more

>>:  Solve the problem of using linuxdeployqt to package Qt programs in Ubuntu

Recommend

...

MySQL optimization strategy (recommended)

In summary: 1. Consider performance when designin...

Introduction to container data volumes in Docker

Table of contents Docker container data volume Us...

Detailed explanation of how to access MySQL database remotely through Workbench

Preface Workbench is installed on one computer, a...

Sitemesh tutorial - page decoration technology principles and applications

1. Basic Concepts 1. Sitemesh is a page decoratio...

How to configure nginx to return text or json

Sometimes when requesting certain interfaces, you...

Steps to build MHA architecture deployment in MySQL

Table of contents MAH 1. Introduction to MAH Arch...

Apache ab concurrent load stress test implementation method

ab command principle Apache's ab command simu...

Methods of adaptive web design (good access experience on mobile phones)

1. Add the viewport tag to the HTML header. At th...

js to realize the function of uploading pictures

The principle of uploading pictures on the front ...

The leftmost matching principle of MySQL database index

Table of contents 1. Joint index description 2. C...

MySQL Database Iron Laws (Summary)

Good database specifications help reduce the comp...