How can we offload the time/date handling in MySQL?


We can offload the time/date handling to MySQL with the help of DATE_FORMAT() function. The date and time would be offloaded on the basis of format units passed as arguments to the function.

For example, when we pass the date format units as arguments to MySQL DATE_FORMAT() function then MySQL offloaded only 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)

Whereas, when we pass the time format units as arguments to MySQL DATE_FORMAT() function then MySQL offloaded only the time as follows −

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)

Updated on: 30-Jan-2020

139 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements