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 function can return values 0 to up to 838.
Syntax :
HOUR(date_value)
Parameter :
- date_value – A DateTime value from which hour portion will be extracted.
Returns : The Hour part from a date.
Example-1 :
SELECT HOUR('2020-05-09 06:11:18.000004');
Output :
6
Example-2 :
SELECT HOUR('837:56:52');
Output :
837
Example-3 :
SELECT HOUR('2018-02-11 11:19:01');
Output :
11
Example-4 :
SELECT HOUR('10:02:06');
Output :
10
Example-5 : Current system time is returned by the CURTIME() function.
SELECT HOUR(CURTIME());
Output :
8
2. FROM_DAYS() Function:
In MariaDB, the FROM_DAYS() function is used to convert a numeric day into a date value. In this function, the first parameter will be a date. This function will convert a given numeric to date. This function is to be used only with dates within the Gregorian calendar.
Syntax :
FROM_DAYS(date)
Parameter :
- date – date(numeric) which will be converted in date value.
Returns : The date value.
Example-1 :
SELECT FROM_DAYS(735919) ;
Output :
'2014-11-17'
Example-2 :
SELECT (FROM_DAYS(780500)- FROM_DAYS(780500));
Output :
0
Example-3 :
SELECT FROM_DAYS(735910);
Output :
'2014-11-08'