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

Some conclusions on developing mobile websites

The mobile version of the website should at least...

The submit event of the form does not respond

1. Problem description <br />When JS is use...

Example of how to upload a Docker image to a private repository

The image can be easily pushed directly to the Do...

Complete steps to reset the root user password in mysql8

Preface Recently, many new colleagues have asked ...

Application of anchor points in HTML

Set Anchor Point <a name="top"><...

Vue+Openlayer realizes the dragging and rotation deformation effect of graphics

Table of contents Preface Related Materials Achie...

How to customize more beautiful link prompt effect with CSS

Suggestion: Handwriting code as much as possible c...

Case study of dynamic data binding of this.$set in Vue

I feel that the explanation of this.$set on the I...

A brief talk about cloning JavaScript

Table of contents 1. Shallow cloning 2. Deep clon...

MySQL database green version installation tutorial to solve system error 1067

What is the difference between the green version ...

Two box models in web pages (W3C box model, IE box model)

There are two types of web page box models: 1: Sta...

Solution to nginx hiding version number and WEB server information

Nginx can not only hide version information, but ...

Javascript Virtual DOM Detailed Explanation

Table of contents What is virtual dom? Why do we ...