Open In App

TO_DAYS Function and WEEK Function in MariaDB

Last Updated : 02 Dec, 2020
Like Article

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 date is ‘0000-00-00’. It is reverse of FROM_DAYS function.

Syntax :

TO_DAYS( date )

Parameter :

Parameter Description
date date to convert to numeric days.

Return :
It returns date into numeric days.

Example-1 :

SELECT TO_DAYS('2014-11-20');

Output :


Example-2 :

SELECT TO_DAYS('2014-11-18 05:30:00');

Output :


Example-3 :

SELECT TO_DAYS('0000-00-00');

Output :


WEEK Function :
In MariaDB, Week Function is used to return the week portion of a date value. In this function, the first parameter will be date value and the second parameter will be mode. This function will return a value between 0-53 or 1-53 depending on the mode specified. This function returns the same as the WEEK function with the syntax of WEEK(date_value, 3).

Syntax :

WEEK( date_value, [ mode ] )

Parameters :

Parameters Description
date value A date or datetime value from which to extract the week.
mode Optional. It is used to specify what day the week starts on.

Return :
It returns the week portion of a date value.

Example :

SELECT WEEK('2020-01-05');

Output :


Like Article
Suggest improvement
Share your thoughts in the comments

Similar Reads