Open In App

LOCALTIME() and LAST_DAY() Function in MariaDB

Last Updated : 18 May, 2022
Improve
Improve
Like Article
Like
Save
Share
Report

1. LOCALTIME() Function : In MariaDB, the LOCALTIME() Function is used to returns the current date and time. In this function, no parameter will be passed. In the string context, the function will return the current date as a ‘YYYY-MM-DD HH:MM: SS’ format. In the numeric context, the function will return the current date in numeric format. Syntax : 

LOCALTIME( )

Parameter : No parameter will be passed in this function. Returns : It will return the current date and time. Example-1 : It will return the current date and time and return in the string format.

SELECT LOCALTIME();

Output : 

'2020-10-25 08:51:16'

Example-2 : It will add 1 unit to the left of current datetime and return in the numeric format.

SELECT LOCALTIME() + 1;

Output : 

20201025085117

Example-3 : It will subtract 6 unit to the left of current datetime and return in the numeric format.

SELECT LOCALTIME() - 6;

Output : 

20201025085110

2. LAST_DAY() Function : In MariaDB, LAST_DAY() function returns the last day of the month for a given date. In this function, the first parameter will be a date_value. This function will return the last day of the month for a given date. If the passed parameterdate_value is not a valid date or DateTime value, the LAST_DAY function would return NULL. Syntax : 

LAST_DAY(date_value)

Parameters : 

  • Date_value – A date or datetime value from which to extract the last day of the month.

Returns : Last day of the given date. Example-1 : 

SELECT LAST_DAY('2010-05-20');

Output : 

'2010-05-31'

Example-2 : 

SELECT LAST_DAY('2016-03-02 11:24:05');

Output : 

'2016-03-30'

Example-3 : 

SELECT LAST_DAY('2020-02-17');

Output : 

'2020-02-29'

Example-4 : 

SELECT LAST_DAY('date is: 2020-08-20');

Output : 

NULL

Example-5 : It will return last day of current month. Today is 28/10/2020.

SELECT LAST_DAY(CURDATE());

Output : 

'2020-10-31'

Example-6 : 

SELECT LAST_DAY('2019-02-11');

Output : 

'2019-02-28'

Like Article
Suggest improvement
Share your thoughts in the comments

Similar Reads