Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
807 views
in Technique[技术] by (71.8m points)

mysql - Format date in SELECT * query

Is it possible to format a date field in a SELECT * query? I want to get all of the columns from my table but need a different format from the date.

Something like:

SELECT *, FORMATDATE(date,'%m-%d-%y') AS date FROM my_table;

or do I have to process it in php after the query?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Use DATE_FORMAT:

SELECT *, DATE_FORMAT(date, "%m-%d-%y") AS date FROM my_table;

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...