Back

Explore Courses Blog Tutorials Interview Questions
0 votes
1 view
in SQL by (20.3k points)

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?

1 Answer

0 votes
by (40.4k points)

Use below code:

DATE_FORMAT(FROM_UNIXTIME(`user.registration`), '%e %b %Y') AS 'date_formatted'

Related questions

0 votes
1 answer
asked Jul 20, 2019 in SQL by Tech4ever (20.3k points)
0 votes
1 answer
0 votes
1 answer
asked Jan 2 in SQL by Appu (6.1k points)
0 votes
1 answer
asked Dec 22, 2020 in SQL by Appu (6.1k points)
Welcome to Intellipaat Community. Get your technical queries answered by top developers!

28.4k questions

29.7k answers

500 comments

94.1k users

Browse Categories

...