简体   繁体   中英

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

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'";

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'";

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM