0

I have date stored in MySQL DB using CURRENT_TIMESTAMP as default, so that when a new data is inserted the date and time is stored automatically. And, I want to retrieve this data and display in my PHP. The retrived data looks like this 2019-03-17 15:02:36 .

Now I need to change it to March 17 2019 in my output.

I tried using date_format() but it is not displaying any output. It just returns blank data.

How can I achieve this.

1
  • Hint: Try it in your statement like `DATE_FORMAT (erstelltam, \"%dth %b %Y at %H:%i:%S Uhr\") AS erstelltam Commented Mar 17, 2019 at 10:41

2 Answers 2

1

The DateTime functions of PHP to the rescue.

$sqldate = '2019-03-17 15:02:36';
$sqldate = DateTime::createFromFormat('Y-m-d G:i:s',$sqldate);
echo $sqldate->format('F d Y');

Produces:

March 17 2019

Sign up to request clarification or add additional context in comments.

Comments

1

Its quite simple use below code

SELECT *, DATE_FORMAT(YOURDATECOLUMN,'%d/%m/%Y') AS niceDate 
FROM table 
ORDER BY YOURDATECOLUMN DESC 

Fiddle : http://sqlfiddle.com/#!9/9eecb/82244

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.