如何将日期转换为与我的数据库不同的格式? [重复]

如何将日期转换为与我的数据库不同的格式?  [重复]

问题描述:

This question already has an answer here:

In my database, dates are stored in this format:

2013-03-14

I want to show dates on my web page formatted as:

2013-march-14

I have a lot of date data already stored in my database, so it's not possible to change my database. How can I do this conversion?

</div>

此问题已经存在 这里有一个答案: p>

  • 如何格式化来自MYSQL的日期 2 answers span> li> ul> div>

    在我的数据库中,日期以这种格式存储: p>

      2013-03-14 
      code>  pre> 
     
     

    我想在我的网页上显示日期格式为: p>

      2013-march-14 
      code>  pre> 
     
     

    我的数据库中已存储了大量日期数据,因此无法更改数据库。 我该怎么做这个转换? p> div>

You can do this

Via MySQL

SELECT DATE_FORMAT(datecolumn, '%Y-%M-%d') FROM table

Via PHP

$date = '2013-03-14';
echo date("Y-F-d", strtotime($date));

Output

2013-march-14

Use the MySQL built-in DATE_FORMAT function, with the specifiers '%Y-%M-%d' to format the date parts the way you want:

SELECT DATE_FORMAT(datefield, '%Y-%M-%d')
...

SQL Fiddle Demo

If you wanted to do this on PHP you could use the date function

$d = '2013-03-04';
echo date("Y-M-d", strtotime($d));  //2013-Mar-04