How to convert timestamp to date in MySQL query

545    Asked by ChrisEVANS in Python , Asked on Jul 12, 2021

I want to convert a timestamp in MySQL to a date.

I would like to format the user.registration field into the text file as a yyyy-mm-dd.

Here is my SQL:

$sql = requestSQL("SELECT user.email, 
                   info.name, 
                   FROM_UNIXTIME(user.registration),
                   info.news
                   FROM user, info 
                   WHERE user.id = info.id ", "export members");

I also tried the date conversion with:

DATE_FORMAT(user.registration, '%d/%m/%Y')
DATE(user.registration)

I echo the result before to write the text file and I get :

email1;name1;DATE_FORMAT(user.registration, '%d/%m/%Y');news1


email2;name2;news2

How can I convert that field to date?


Answered by Dhananjay Singh

Try this to solve mysql convert timestamp to date error:

DATE_FORMAT(FROM_UNIXTIME(`user.registration`), '%e %b %Y') AS 'date_formatted'
Hope this help!!
Thank you!

Your Answer

Interviews

Parent Categories