Shamsh Sameed Ahsan
Shamsh Sameed Ahsan

Reputation: 57

Display Only Month From Mysql Database

This code displays date as: 13-07-2016 I want to display only month and year. Example: "July 2016" How do I modify this code so that it gets Only month and year and displays it. Code:

   <td><?=$this->wll->getDateFormate(6,$row['bill_date'])?></td>

Upvotes: 0

Views: 304

Answers (5)

Jade Kallo
Jade Kallo

Reputation: 110

$date = $row['bill_date'];
$month = date('F', strtotime($date));
$year = date('Y', strtotime($date));

<td><?php echo $month . ' ' . $year; ?></td>

Upvotes: 1

Kalyan Singh Rathore
Kalyan Singh Rathore

Reputation: 57

date_format($row['bill_date], "F Y");

F -> Full Month Letters and Y -> 4 digit Year

Upvotes: 0

RiggsFolly
RiggsFolly

Reputation: 94662

In that case amend your query to provide that data you want to use rather than trying to manipulate it post query

SELECT DATE_FORMAT(theDateCol, '%M %Y') as theMonthAndYear, ...

Upvotes: 0

LeviZoesch
LeviZoesch

Reputation: 1621

Use strtotime():

$time=strtotime($dateValue);
$month=date("F",$time);
$year=date("Y",$time);

Or you can do something like...

$dateElements = explode('-', $dateValue);
$year = $dateElements[0];

echo $year;    //2012

switch ($dateElements[1]) {

   case '01'    :  $mo = "January";
                   break;

   case '02'    :  $mo = "February";
                   break;

   case '03'    :  $mo = "March";
                   break;

     .
     .
     .

   case '12'    :  $mo = "December";
                   break;


}

echo $mo;      //January

Upvotes: 0

Ilan Olkies
Ilan Olkies

Reputation: 453

Try using a switch on your display text. Something like this:

var month_number = display_text[3] + display_text[3];
var month;
switch (month_number)
    case "01":
        month = "Jan";
        break;
...

And display thath month with the other characters, like:

show: display_text[0] + display_text[1] + "-" + month + ...

Upvotes: 0

Related Questions