MySQL MAKEDATE() Function
MySQL MAKEDATE(): Construct a Date From Year and Day of Year
The MAKEDATE() function creates a DATE value from two integers: a year and a dayofyear count (1 or greater). It converts ordinal dates (like day 100 of 2026) directly into standard 'YYYY-MM-DD' dates.
Reporting jobs and fiscal calendars use MAKEDATE() to reconstruct dates from ordinal day indexes or generate January 1 anchors (MAKEDATE(YEAR(d), 1)).
Syntax
Pass the 4-digit year first and the day-of-year integer second:
MAKEDATE(year, dayofyear)
year: An integer year between0and9999.dayofyear: A positive integer (>= 1). Values greater than365(or366in leap years) roll forward into subsequent years!
Practical Example
Suppose your logistics team tracks shipping target days as ordinal day numbers (target_day_of_year) in a yearly schedule alongside demo_orders.
SELECT
order_id,
order_date,
MAKEDATE(YEAR(order_date), 1) AS year_start,
MAKEDATE(2026, 60) AS day_60_common,
MAKEDATE(2024, 60) AS day_60_leap,
MAKEDATE(2026, 366) AS overflow_rollover
FROM demo_orders
WHERE order_id = 101;
| order_id | order_date | year_start | day_60_common | day_60_leap | overflow_rollover |
|---|---|---|---|---|---|
| 101 | 2026-05-12 | 2026-01-01 | 2026-03-01 | 2024-02-29 | 2027-01-01 |
Notice how day 60 lands on March 1 in 2026 but February 29 in leap year 2024, and day 366 in 2026 rolls over into 2027-01-01.
Common Mistakes & NULL Behavior
Avoid these traps when calling MAKEDATE():
dayofyear <= 0returnsNULL: Passing0or a negative number likeMAKEDATE(2026, 0)returnsNULLrather than rolling backward into the previous year.- Day numbers above 365 do NOT return
NULL:MAKEDATE(2026, 400)rolls into2027-02-04. Check your inputs if you did not intend multi-year rollover. - Two-digit years are literal:
MAKEDATE(26, 1)returns'0026-01-01', NOT'2026-01-01'. Always pass a 4-digit year. NULLor out-of-range years returnNULL: If either argument isNULL, or ifyear < 0oryear > 9999,MAKEDATE()returnsNULL.
Frequently Asked Questions
How can I get the first day of the current year in MySQL?
Run MAKEDATE(YEAR(CURDATE()), 1), which cleanly returns '2026-01-01' without string concatenation.
Why did MAKEDATE(2026, 366) return 2027-01-01 instead of an error?
2026 is not a leap year and has 365 days, so MySQL advances 366 days from January 1 and rolls forward to January 1, 2027.
Is there a function to build a date from year, month, and day separately?
MySQL has no MAKEDATE(year, month, day) overload. Use STR_TO_DATE(CONCAT(y, '-', m, '-', d), '%Y-%m-%d') instead.
Unlock Your
Full Potential.
Sign in to track your learning journey, earn industry-recognized certificates, and join our elite developer community.
Quick Access With
Try it Yourself
Experiment with the code from this lesson in our interactive playground.