Skip to content
Related Articles

Related Articles

MAKEDATE() and LOCALTIMESTAMP() Function in MariaDB

Improve Article
Save Article
  • Last Updated : 15 Jun, 2022
Improve Article
Save Article

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 return NULL. Syntax :

MAKEDATE(year, day-of-year)

Parameters : Required. Two parameters.

  • year – 4-digit year used for creating the date.
  • day-of-year – A day of the year (greater than 0) used for creating the date.

Returns : It returns the date for a certain year and day-of-year value. Example-1 :

SELECT MAKEDATE(2020, 1);

Output :

'2020-01-01'

Example-2 :

SELECT MAKEDATE(2020, 42);

Output :

'2020-02-11'

Example-3 :

SELECT MAKEDATE(2019, -12);

Output :

NULL

Example-4 :

SELECT MAKEDATE(2019, 366);

Output :

'2020-01-01'

Example-5 :

SELECT MAKEDATE(2020, 366);

Output :

'2020-12-31'

2. LOCALTIMESTAMP() Function : In MariaDB, the LOCALTIMESTAMP() Function is used to return the current date and time. In this function, no parameter will be passed. This function will return the current timestamp. For string context, this function will return the current date as a ‘YYYY-MM-DD HH:MM: SS’ format. For numeric context, this function will return the current date as a YYYYMMDDHHMMSS format. This function works similarly to the LOCALTIME() function. Syntax :

LOCALTIMESTAMP( )

Parameters : No parameter will be passed. Returns : It will return the current timestamp. Example-1 : 

SELECT LOCALTIMESTAMP();

Output :

'2020-10-25 12:52:35'

Example-2 : It will add 10 unit from right of current timestamp.

SELECT LOCALTIMESTAMP()+10;

Output :

'20201025125225'

Example-3 : It will subtract 5 unit from right of current timestamp.

SELECT LOCALTIMESTAMP()-5;

Output :

'20201025125230'
My Personal Notes arrow_drop_up
Related Articles

Start Your Coding Journey Now!