SELECT LAST_DAY( '2016-12-25' )
Output is 2016-12-31 LAST_DAY(date)
DEMO: Select date from Calendar to execute LAST_DAY() SELECT LAST_DAY('2016-09-13 12:59:45')
Output is 2016-09-30select DATE_FORMAT(LAST_DAY('2016-09-15'),'%W %D %M %Y')
Output is Friday 30th September 2016
SELECT LAST_DAY( NOW( ) )
SELECT LAST_DAY(CURDATE() - INTERVAL 1 MONTH)
CURDATE() to get First day and last day of previous Month
SELECT * FROM `dt_table` WHERE date between DATE_FORMAT(CURDATE() ,'%Y-%m-01') AND CURDATE()
SELECT IF( DAYOFWEEK( LAST_DAY( NOW( ) ) ) =1, DATE_ADD( LAST_DAY( NOW( ) ) , INTERVAL -1 DAY ) , LAST_DAY( NOW( ) ) )
Try this
SELECT IF( DAYOFWEEK( LAST_DAY( '2016-07-20' ) ) =1, DATE_ADD( LAST_DAY( '2016-07-20' ) , INTERVAL -1 DAY ) , LAST_DAY( '2016-07-20' ) )
Output is 2016-07-30
<?Php
require 'config.php'; // Database connection string
$query='SELECT LAST_DAY( 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;
?>
Output is : 2026-09-30;
Author & Instructor at plus2net
I write and maintain practical tutorials on Python, PHP, SQL, JavaScript, HTML, jQuery, and web development at plus2net. The tutorials focus on clear explanations, working examples, and code that readers can test and adapt while learning.