MAKEDATE( )

This MySQL function determines the date requested from the start of the given year, by adding the number of days given.

Syntax

Below is the syntax for this command. Text within square brackets (i.e, [ and ] ) are optional. Choices are separated by bars (i.e, | ). Ellipses preceded by a comma indicates a repeating pattern. Ellipses before or after syntax are used to highlight a relevant except from the larger syntax. Text displayed in italic letters represent text that should be replaced with the specific names related to the database (e.g., column with the name of the column).

MAKEDATE(year, days)

Explanation

This function determines the date requested from the start of the given year, by adding the number of days given in the second argument. It returns the date in the yyyy-mm-dd format. It returns NULL if a value given for days is not greater than 0. It will accept more than a year's worth of days, though. It just returns a date into the next year or whatever year is appropriate, based on however many days the result is from the beginning of the year given. This function is available as of version 4.1.1 of MySQL.

Examples

SELECT MAKEDATE(2009, 1) AS 'First Day',
MAKEDATE(2009, 365) AS 'Last Day',
MAKEDATE(2009, 366) AS 'One More Day';

+------------+------------+--------------+
| First Day  | Last Day   | One More Day |
+------------+------------+--------------+
| 2009-01-01 | 2009-12-31 | 2010-01-01   | 
+------------+------------+--------------+