-2

I have a following code and in this news_date is of datatype DATE.

<?php 
     $news_id=$_REQUEST['id'];   
        $result = mysql_query("select news_title, img_name, news_date, news_desc from news where news_id=".$news_id);
        $row=mysql_fetch_array($result);
      ?>

.

   <div class=news-date>
        <?php echo $row['news_date'] ?>
    </div>

This gives me date in "YYYY-mm-dd" format. How can i change it to "mmmm-dd-yyyy" i.e. October 24, 2013 or similar

mawburn
  • 2,232
  • 4
  • 29
  • 48
vishalkin
  • 1,175
  • 2
  • 12
  • 24
  • [**Please, don't use `mysql_*` functions in new code**](http://bit.ly/phpmsql). They are no longer maintained [and are officially deprecated](https://wiki.php.net/rfc/mysql_deprecation). See the [**red box**](http://j.mp/Te9zIL)? Learn about [*prepared statements*](http://j.mp/T9hLWi) instead, and use [PDO](http://php.net/pdo) or [MySQLi](http://php.net/mysqli) - [this article](http://j.mp/QEx8IB) will help you decide which. If you choose PDO, [here is a good tutorial](http://j.mp/PoWehJ). – h2ooooooo Oct 24 '13 at 17:34
  • @h2ooooooo. Well thanks for that.. I will improve my code. – vishalkin Oct 25 '13 at 02:03

2 Answers2

1

Use strtotime() and date():

echo date('m-d-Y', strtotime($row['news_date']));
h2ooooooo
  • 39,111
  • 8
  • 68
  • 102
0

This worked for me.

<?php 
     $news_id=$_REQUEST['id'];   
        $result = mysql_query("select news_title, img_name, news_date, news_desc from news where news_id=".$news_id);
        $row=mysql_fetch_array($result);
        $datetime= $row['news_date'];
        $datetime=date("F j, Y ") 
      ?>

<div class="clearfix" title="news date"><strong><?php echo  $datetime ?></strong>
    </div>
vishalkin
  • 1,175
  • 2
  • 12
  • 24