Directory:
- Common date functions
- Time-plus-decrement function
- Date_forma function
1. Common date functions
Now () Current_timestamp () sysdate ()
You can see that three functions are used to get the current system time.
In the operation, the sleep function was added, waiting for 2 seconds, then found that the Sysdate function and the other two functions to get the value of different, sysdate function to get the value of 2 seconds faster. So three functions are slightly different, the difference is as follows:
Current_timestamp and now are synonyms, and the two are the same.
The Sysdate function returns the time it takes to execute to the current function, and now returns the time when the SQL statement was executed.
2. Time-plus-decrement function
Date_add (date, interval expr unit) date_sub (date, interval expr unit)
The value of expr can be positive or negative, so you can use the Date_add function to do the work of the Date_sub function, for example:
In the above example, the unit parameter uses day, hour, in fact, you can also use microsecond, second, minute, week, month, year and other types.
3. Date_format function
Select ' %y%m%d ' as DateTime;
Operation Result:
Mysql date and time-related functions