SELECT MONTHNAME('2023-01-01'); # January
SELECT MONTHNAME('2023-12-31');# December
SELECT MONTHNAME('2023-02-31');# NULL
Returns full month name from a date. MONTHNAME()
Example :
SELECT MONTHNAME('2016-09-25')
Output is September
SELECT MONTHNAME(CURDATE())
Output is February
SELECT date_format(date,'%b') as dt FROM table_name
SELECT * FROM `table_name` WHERE DATE_FORMAT(date, '%b')='Jan'
SELECT * FROM `table_name` WHERE DATE_FORMAT( date, '%M' ) = 'January'
SELECT MONTHNAME(CURDATE()- interval 1 month) as LastMonth,
MONTHNAME(CURDATE()) as PresentMonth,
MONTHNAME(CURDATE()+ interval 1 Month) as NextMonth
Last Month | PresentMonth | NextMonth |
January | February | March |
config.php connection string is available here
PDO for executing Queries in PHP
How to get records using FETCH() are here
<?Php
require 'config.php'; // Database connection string
$query='SELECT MONTHNAME(NOW()) as dt';
// Change the above Query part to get different results //
$count=$dbo->prepare($query);
$count->execute();
$row = $count->fetch(PDO::FETCH_OBJ);
echo 'Output is : '.$row->dt;
?>
SQL Date MONTH() : Month number from 1 to 12