0

i have dates taht are saved in the database in the format of YYYY-mm-dd (ex. 2013-01-31). In some areas I need to display the date as MMM dd, YYYY (ex. Jan 31, 2013). Can anyone help me in this converting.

I am using php and a mysql database. So far I have this to separate the date values, but dont know how to change them to what I want:

list($BYear, $BMonth, $BDay) = explode('-', $DateOfBirth);
$CYear = date('Y');
$CMonth = date('m');
$CDay = date('d');

Thanks in advance.

Lajos Veres
  • 13,595
  • 7
  • 43
  • 56
user1257948
  • 21
  • 1
  • 4
  • What kind of database? How are you displaying them? Is this a web application? Desktop application with GUI? Command line? What language? – Joseph Oct 11 '13 at 20:51
  • sorry - using php and mysql – user1257948 Oct 11 '13 at 20:52
  • Okay, please update your question to be more specific. And please tell us what you've already tried. Don't ask others to do your work for you: try something, watch it fail, figure out why, repeat until it works. Ask questions _along_the_way_. – bedwyr Oct 11 '13 at 20:52
  • possible duplicate of [Convert one date format into another in PHP](http://stackoverflow.com/questions/2167916/convert-one-date-format-into-another-in-php) – Ben Apr 19 '14 at 07:09

3 Answers3

1

http://dev.mysql.com/doc/refman/5.1/en/date-and-time-functions.html#function_date-format

select date_format(field, '%M %d, %Y') from table;
Lajos Veres
  • 13,595
  • 7
  • 43
  • 56
1

If you only want display then you can use this.

<?php echo date("M d, Y", strtotime($DateOfBirth)); ?>

Nanhe Kumar
  • 15,498
  • 5
  • 79
  • 71
  • 1
    thanks a bunch works like a charm - i am completing someone elses work and have very little experience in php. – user1257948 Oct 11 '13 at 21:12
0

try :

select convert(varchar(20),@YOUR_DATE,107)
Jonysuise
  • 1,790
  • 13
  • 11