Name

MAKEDATE()

Synopsis

MAKEDATE(year, days)

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. Here is an example:

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   | 
+------------+------------+--------------+

Get MySQL in a Nutshell, 2nd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.