Home  >  Article  >  Database  >  How to input datetime data in mysql

How to input datetime data in mysql

coldplay.xixi
coldplay.xixiOriginal
2020-10-09 15:33:4413959browse

Mysql method of inputting datetime data: 1. Use the function [now()] to input; 2. Use the function [current_timestamp()] to input; 3. Use the function [,current_timestamp] to input; 4. Use the function 【,localtime()】Input.

How to input datetime data in mysql

Mysql method of inputting datetime data:

Programming example for obtaining Date Time data:

mysql> select now();
| now()               | 
| 2008-08-08 22:20:46 |

In addition to the now() function that can obtain the current date and time, MySQL also has the following functions:

  • current_timestamp()

  • ,current_timestamp

  • ,localtime()

  • ,localtime

  • ,localtimestamp -- (v4.0.6)

  • ,localtimestamp() -- (v4.0.6)

These date and time functions are equivalent to now( ). Since the now() function is short and easy to remember, it is recommended to always use now() instead of the functions listed above.

How to input datetime data in mysql

Extended information:

Types of MySql’s time and date functions (Date Time):

1. Function ADDDATE(date, INTERVAL expr type) ADDDATE(expr, days)

Function usage instructions: When activated by the INTERVAL format of the second parameter, ADDDATE() is a synonym for DATE_ADD(). The related function SUBDATE() is a synonym for DATE_SUB(). For information on the INTERVAL parameter, see the discussion of DATE_ADD().

2. Function ADDTIME(expr, expr2)

Function usage instructions: ADDTIME() adds expr2 to expr and returns the result. expr is a time or time-date expression, and expr2 is a time expression.

3. Function CONVERT_TZ (dt, from_tz, to_tz)

Function instructions: CONVERT_TZ() transfers the time and date value dt from the time zone given by from_tz to the time zone given by to_tz, and then Return the result value. For a detailed discussion of the possible specified time zones, if the independent variable is invalid, this function will return NULL

Related free learning recommendations:mysql database(video)

The above is the detailed content of How to input datetime data in mysql. For more information, please follow other related articles on the PHP Chinese website!

Statement:
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
Previous article:How to restore mysql logNext article:How to restore mysql log