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

MySQLMySQLi Database

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)
raja
Published on 19-Feb-2018 16:05:22
Advertisements