00 Votes

MySQL: Convert Unix Timestamp to Date

Question by Compi | 2016-03-10 at 12:52

I am getting a Unix Timestamp from one of my MySQL queries, that is a long number such as 1517440125 that is not really readable.

Because of that, I would like to transform this number into a readable format or a real date before reading out. I know the MySQL command UNIX_TIMESTAMP() with which you are able to convert a date into a Unix Timestamp, but isn't there any function to reverse that?

ReplyPositiveNegative
0Best Answer0 Votes

Yes, there is a function.

It is called FROM_UNIXTIME and you can use it with or without parameter.

SELECT FROM_UNIXTIME(1517440125);

-> '2018-02-01 00:08:45'

Without parameter the result will be this format. If you want to determine your own format, you can pass the formatting as parameter:

SELECT FROM_UNIXTIME(1517440125, '%d.%m.%Y %H%i%s');

-> '01.02.2018 00:08:45'

As you can see, %d is standing for the day, %m for the month, %Y for the year and so on. You can use other characters between those placeholders like points or spaces as you can see in the example.
2016-03-10 at 14:23

ReplyPositive Negative
Reply

Related Topics

PHP: Current Date and Time

Tutorial | 0 Comments

PHP: Determine Week Number

Tutorial | 0 Comments

Change Date of File

Tutorial | 0 Comments

Important Note

Please note: The contributions published on askingbox.com are contributions of users and should not substitute professional advice. They are not verified by independents and do not necessarily reflect the opinion of askingbox.com. Learn more.

Participate

Ask your own question or write your own article on askingbox.com. That’s how it’s done.