SACHIN HD
SACHIN HD

Reputation: 45

Display date as MONTH YEAR format from Mysql using PHP

This is the query datemade is date datatype in MYSQL

     $sqlCommand ="SELECT blogbody,datemade FROM blogpages WHERE bpid='$blogid'";

This is the fetch array

        $dmade=$row["datemade"];

I echo out the date how can we display it as ex: November 2014

Upvotes: 0

Views: 2380

Answers (2)

manlikeangus
manlikeangus

Reputation: 421

Just use MySQL DATE_FORMAT function.

Change your query to:

$sqlCommand ="SELECT blogbody, DATE_FORMAT(datemade, '%M %Y') AS datemade FROM blogpages WHERE bpid='$blogid'";

Upvotes: 0

ekad
ekad

Reputation: 14614

Use DATE_FORMAT function with '%M %Y' as the format parameter to display month name and four digit year like below

DATE_FORMAT(datemade, '%M %Y')

This is the modified query

$sqlCommand = "SELECT blogbody, DATE_FORMAT(datemade, '%M %Y') AS datemade FROM blogpages WHERE bpid='$blogid'";

Upvotes: 1

Related Questions