We can offload time/date processing to MySQL with the help of the DATE_FORMAT() function. The date and time will be unloaded according to the format units passed as arguments to the function.
For example, when we pass the date format unit as a parameter to the MySQL DATE_FORMAT() function, MySQL only unloads the date as follows -
mysql> Select DATE_FORMAT("2017-10-22 13:03:45", "%Y %M %D")AS 'OFFLOADED DATE'; +-------------------+ | OFFLOADED DATE | +-------------------+ | 2017 October 22nd | +-------------------+ 1 row in set (0.00 sec)
However, when we pass the time format unit as a parameter to MySQL only unloads the time when using the DATE_FORMAT() function as shown below -
mysql> Select DATE_FORMAT("2017-10-22 13:03:45", "%h %i %s %p")AS 'OFFLOADED TIME'; +----------------+ | OFFLOADED TIME | +----------------+ | 01 03 45 PM | +----------------+ 1 row in set (0.00 sec)
The above is the detailed content of How do we offload time/date processing in MySQL?. For more information, please follow other related articles on the PHP Chinese website!