Muhammad Arif Muhammad Arif - 7 months ago 10
PHP Question

how to convert dateformat in php?

I get the data from database, which gives me the date in a format like

2014-01-06 06:13:06
. I want to convert that date into the format
Jan 6th 2014
. Here is my code:

<?php
$query="SELECT Min(transaction_date) as start,Max(transaction_date) as end from transactions";
$result1= mysql_query($query) or die(mysql_error());
$ors1=mysql_fetch_array($result1);
$date= $ors1['start'];
echo date_format($date, 'g:ia \o\n l jS F Y');
?>

Answer

Try this one

 <?php 
    $query="SELECT Min(transaction_date) as start,Max(transaction_date) as end from transactions";
    $result1= mysql_query($query) or die(mysql_error());
    $ors1=mysql_fetch_array($result1);
    $date= $ors1['start'];
    echo date('dS M Y' ,strtotime($date));
 ?>

Reference url : PHP Documentation

Comments