LAST_DAY() Last Day of the month in MySQL QuerySyntax of LAST_DAY()
Output is 2016-12-31 With datetime
Output is 2016-09-30 We can use DATE_FORMAT() to change the output
Output is Friday 30th September 2016
What is the last date of current month? Now() returns the present date and time
LAST DAY OF Previous Month
Present Month RecordsStarting from 1st day of the current month till now. ( there is no FAST_DAY() function to get the 1st day of the month).
Get the last working day of the monthSunday is not a working day of the month, so to get the last working day of the month we have to use weekday() function and then use IF function to check condition to change the date by 1 if last_day() returns SUNDAY , to get the last working day of the month.
Output is 2016-07-30
Now let us try again the last date of current month. Output is : 2019-04-30
PHP ScriptTo display the above details we used PHP Script, you can use the same script for using all above queries.
To run this PHP Script have to first connect to MySQL database. All details of connection string is available here.
We have used PDO for executing Queries in PHP, details on how to get records using FETCH() are here.
Output is : 2019-04-30;