[英]How to convert datetime stored in MySQL, to a different format using php
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. 我将日期默认存储在MySQL DB中,使用
CURRENT_TIMESTAMP
作为日期,以便在插入新数据时自动存储日期和时间。 And, I want to retrieve this data and display in my PHP
. 而且,我想检索这些数据并显示在我的
PHP
。 The retrived data looks like this 2019-03-17 15:02:36
. 检索到的数据看起来像这样
2019-03-17 15:02:36
。
Now I need to change it to March 17 2019
in my output. 现在我需要在输出中将其更改为
March 17 2019
。
I tried using date_format()
but it is not displaying any output. 我尝试使用
date_format()
,但未显示任何输出。 It just returns blank data. 它只是返回空白数据。
How can I achieve this. 我该如何实现。
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 小提琴: http ://sqlfiddle.com/#!9/9eecb/ 82244
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.