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?
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?
<?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
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
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.
<?php
$date=new DateTime('2010-01-30');
echo $date->format('F d, Y')."<BR>";
echo $date->format('M. d, Y');
?>