Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

change the integer time to date format MM/DD/YY like datetime.fromtimestamp in python

I have a table as follow. In python with datetime.fromtimestamp we can change the integer time to date. I want to change the time column to MM/DD/YY in Mysql. Can you help me with that?

enter image description here

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

mysql> select from_unixtime(1546322400) as date;
+---------------------+
| date                |
+---------------------+
| 2018-12-31 22:00:00 |
+---------------------+

mysql> select date_format(from_unixtime(1546322400), '%m/%d/%Y') as date;
+------------+
| date       |
+------------+
| 12/31/2018 |
+------------+

I forgot until the comment from nbk above that FROM_UNIXTIME() does support an optional second argument, so you can do this in one step:

mysql> select from_unixtime(1546322400, '%m/%d/%Y') as date;
+------------+
| date       |
+------------+
| 12/31/2018 |
+------------+

Read about DATE_FORMAT()
and FROM_UNIXTIME().

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading