Current date and time functions in mysql

下次还敢
Release: 2024-04-29 03:45:21
Original
614 people have browsed it

There are three functions in MySQL to obtain the current date and time: 1. NOW() function: returns the current date and time in the format of 'YYYY-MM-DD HH:MM:SS'; 2. CURDATE () Function: Returns the current date in the format of 'YYYY-MM-DD'; 3. CURTIME() Function: Returns the current time in the format of 'HH:MM:SS'.

Current date and time functions in mysql

Function to get the current date and time in MySQL

NOW() function

NOW() function returns the current date and time in the format of 'YYYY-MM-DD HH:MM:SS'.

Example:

SELECT NOW();
Copy after login

Result:

2023-03-08 14:32:31
Copy after login

CURDATE() function

CURDATE() function returns the current date in the format of 'YYYY-MM-DD'.

Example:

SELECT CURDATE();
Copy after login

Result:

2023-03-08
Copy after login

CURTIME() function

CURTIME() function returns the current time in the format of 'HH:MM:SS'.

Example:

SELECT CURTIME();
Copy after login

Result:

14:32:31
Copy after login

Other usage

In addition to using these functions alone, they can also be used in combination with other functions, such as:

  • DATE_ADD():Add the specified number of days or time to the current date or time.
  • DATE_SUB():Subtract the specified number of days or time from the current date or time.
  • DATE_FORMAT():Convert a date or time to a different format.

Note:

These functions return the current date and time on the server, not the date and time on the client computer.

The above is the detailed content of Current date and time functions in mysql. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
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
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!