-1

I am pulling a date from a MySQL database that is formatted 2010-01-30. What I need is to convert it to format Jan. 30, 2010 or January 30, 2010.

Is there a simple way to do this in PHP?

AlexP
  • 9,906
  • 1
  • 24
  • 43

4 Answers4

1
<?php
$date = '2010-01-30';
$dt = new DateTime($date);
echo $dt->format('M. d, Y'); 

Supported Formats: http://www.php.net/manual/en/datetime.formats.php

Jessica
  • 7,075
  • 28
  • 39
1

Assuming the date exists as '2010-01-30' in $date_variable variable:

$formatted_date = date( 'M d, Y', strtotime( $date_variable ) );

strtotime() converts any date string into the # of seconds since UNIX epoch. We feed this back into date() as second parameter with the format string 'M d, Y'. Additional formatting options here

Patrick Moore
  • 13,251
  • 5
  • 38
  • 63
1

It's simple way to do that it's one of solution:

<?php echo date("M. d, Y",strtotime("2010-01-30")); ?>

It will give you: Jan. 30, 2010 If it's all you need - click solved.

JDSolutions
  • 115
  • 6
0
<?php
$date=new DateTime('2010-01-30');
echo $date->format('F d, Y')."<BR>";
echo $date->format('M. d, Y');
?>
chiliNUT
  • 18,989
  • 14
  • 66
  • 106
  • TIP: Add a dot in `echo $date->format('M d, Y');` just after the `M` --- *"What I need is to convert it to format Jan. 30, 2010"* <= OP ;-) – Funk Forty Niner Dec 27 '13 at 17:37