MONTHNAME() : Full Month name in MySQL
Returns full month name from a date.
DEMO: Select date from Calendar to execute MONTHNAME()
Video Tutorial on date function MONTHNAME()
CURDATE() or NOW() & MONTHNAME()
By using CURDATE() we get the present date part only, where as by using NOW() we will get both date and time.
To get short month name as Jan, Feb ... you can use Date format.
SELECT date_format(date,'%b') as dt FROM table_name
Last Month , Today and Next Month
SELECT MONTHNAME(CURDATE()- interval 1 month) as LastMonth,
MONTHNAME(CURDATE()) as PresentMonth,
MONTHNAME(CURDATE()+ interval 1 Month) as NextMonth
Last Month PresentMonth NextMonth
December January February PHP Script
To display the above details we used PHP Script, you can use the same script for using all above queries.
config.php connection string is available here
PDO for executing Queries in PHP
How to get records using FETCH() are here
require 'config.php'; // Database connection string
$query='SELECT MONTHNAME(NOW()) as dt';
// Change the above Query part to get different results //
$row = $count->fetch(PDO::FETCH_OBJ);
echo 'Output is : '.$row->dt;
SQL Date MONTH() : Month number from 1 to 12
SQL txt file for MONTHNAME()
This article is written by
Be the first to post comment:
▼ More on Date & Time functions in SQL