LOCALTIME() and LAST_DAY() Function in MariaDB
Last Updated :
18 May, 2022
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'
Similar Reads
MAKEDATE() and LOCALTIMESTAMP() Function in MariaDB 1. MAKEDATE() Function : In MariaDB, the MAKEDATE() Function is used to return the date for a certain year and day-of-year value. In this function, the first parameter will be a year and the second parameter will be the day of the year. If day-of-year is less than 1, the MAKEDATE function will retur
2 min read
LN(), LOG10() AND LOG2() FUNCTION in MariaDB 1. LN() Function : In MariaDB, the LN() function is used for the natural logarithm of a number. In this function, a number will be passed as a parameter and it will return the natural logarithm of that. The number which will be passed must be greater than 0. If the number is less than 0 or equal to
2 min read
Date and Time Functions in PL/SQL Date and Time Functions in PL/SQL are useful for date and time operations like extracting date components, performing date arithmetic, and converting between date formats. Date and Time Functions in PL/SQLThere are many useful Date and Time functions in PL/SQL. A table of such functions along with t
4 min read
HOUR() and FROM_DAYS() function in MariaDB 1. HOUR() Function : In MariaDB, the HOUR() function is used to return the hour portion of a date value. In this function, the first parameter will be date_value. This function will return HOUR part of the given date. Since a time value can be range from -838:59:59' to '838:59:59' so that this funct
2 min read
TO_DAYS Function and WEEK Function in MariaDB TO_DAYS Function : In MariaDB, TO_DAYS Function converts a date into numeric days. In this function, the first parameter will be the Date. This function returns the numeric days of the date. This function is to be used only with dates within the Gregorian calendar. This function will return NULL if
2 min read