Open In App

MAKEDATE() function in MySQL

Last Updated : 26 Nov, 2020
Improve
Improve
Like Article
Like
Save
Share
Report

MAKEDATE() :
This function in MySQL is used to create and return a date based on a year and a number of days value. The number of days must be greater than 0 otherwise it returns a NULL value.

Syntax :

MAKEDATE(year, day)

Parameter : 

This function accepts two parameters as given below as follows.

  • year – It indicates the year which we want to create.
  • day – It indicates the days of a year which we want to create.

Returns :

It returns a date based on a year and a number of day’s value.

Example-1 :

Creating and returning a date based on a year and a number of days value. Here the date is taken as 2020 and the no of days is 31.So, MAKEDATE function will return the date 31-01-2020.

SELECT MAKEDATE(2020,31) AS NEWDATE ;

Output :

NEWDATE 
2020-01-31

Example-2 :

Creating and returning a date based on a year and a number of days value. Here the date is taken as a 2020 and the no of the day is less than 0.So, MAKEDATE function will return NULL.

SELECT MAKEDATE(2020,-1) AS NEWDATE ;

Output :

NEWDATE 
NULL

Example-3 :

Creating and returning a date based on a year and a number of days value. Here the date is taken as a 2020 and the no of day is 366.So, MAKEDATE function will return last day in the year as it is a leap year.

SELECT MAKEDATE(2020,366) AS NEWDATE ;

Output :

NEWDATE 
 2020-12-31

Example-4 :

Creating and returning a date based on  a year and a number of days value. Here the date is taken as 2015 and the no of the day is 366.So, MAKEDATE function will return first day in the next year i.e 01/01/2016.

SELECT MAKEDATE(2015,366) AS NEWDATE ;

Output :

NEWDATE 
2016-01-01

Like Article
Suggest improvement
Share your thoughts in the comments

Similar Reads