-4

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?

Michael Petrotta
  • 59,888
  • 27
  • 145
  • 179
User
  • 360
  • 3
  • 4
  • 18

3 Answers3

0

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

Mahmoud Gamal
  • 78,257
  • 17
  • 139
  • 164
0

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
rantsh
  • 608
  • 10
  • 30
0

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
Sumit Bijvani
  • 8,154
  • 17
  • 50
  • 82
  • 1
    actually on PHP M would give you Mar not march, I can't remember what the format for full month is and for whatever reason the stupid manual not loading right now – rantsh Mar 16 '13 at 06:29
  • 1
    @rantsh for full month `echo date("Y-F-d", strtotime($date));` – Sumit Bijvani Mar 16 '13 at 06:34