---
title: Your database will break in 2038 (or sooner)
url: "https://aaronfrancis.com/videos/your-database-will-break-in-2038-or-sooner"
path: "/videos/your-database-will-break-in-2038-or-sooner"
type: video
author: Aaron Francis
published: 2023-10-12
topic: Databases
keywords: [mysql, timestamp, unix timestamp, y2k38, datetime, timezone, mysql timestamps, timestamp overflow, planetscale]
youtube_url: "https://www.youtube.com/watch?v=d6HaTHkXqcQ"
site_index: "/llms.txt"
keyword_index: "/llms/keywords.txt"
---

# Your database will break in 2038 (or sooner)

## Chapters

- The 2038 problem
- Proving the problem
- Timestamp functions
- How to fix the problem
- Datetimes and timezones
- Full MySQL course

## Transcript

**Aaron Francis:** MySQL has a 2038 problem. And if you don't know what the 2038 problem is, it's kind of like the Y2K problem. I was 10 at the time, and I remember people lost their minds. At the stroke of midnight, elevators may stop. Airplanes and trains may come to a halt. Heat may vanish. Heat may vanish. The 2038 problem is not that serious.

**Aaron Francis:** I can promise you that. You don't need to stock up on anything. You might hear this problem referred to as Y2K38, which feels a little bit derivative to me. You might hear it called the Y2038 problem, which is a little straightforward. You might hear it called the epochalypse, which earns my highest marks because it is exceedingly clever with the wordplay, because this whole issue revolves around the Unix epoch.

**Aaron Francis:** So MySQL's problem here is that the timestamp column is a four-byte column, and the legal range is from the Unix epoch, which is the very beginning of 1970, all the way to 2038, which is where we get the name, 2038-01-19 at 03:14:07 UTC. That is the legal range of the timestamp column in MySQL.

**Aaron Francis:** So if you try to store anything beyond that legal range, you get an error that says this value is out of bounds. This is the 2038 problem. Let's see if we can prove it. Let's create a table called epochs, and in this table, we're gonna put two columns. We're gonna put a timestamp, and we're gonna put a date time. Now, the date time is similar to the timestamp.

**Aaron Francis:** A timestamp is four bytes. A date time is eight bytes. And there is another difference, and that relates to how they treat time zones, but we'll talk about that in a second. So let's create this table and then insert into epochs the timestamp and the date time. And for these values, let's just start by doing 2038-01-01 in both columns.

**Aaron Francis:** So hopefully, this is going to work, and that will just insert. We can do select star from epochs, and it looks like we're good so far. Now, here's the issue. If we change these to 2039 and we run that, we see that for column TS, it failed. That's because it's outside of the legal range that is acceptable.

**Aaron Francis:** So let's change this one back and see if it works for date time, and sure enough, it does. So now if we read this back, we see that date time, you can store beyond 2038. I think you can store up to 9,000-- the year 9999, so you should be good there. Um, but with a timestamp, you are capped at 2038. This is the most impactful place that this problem presents itself is in this timestamp column.

**Aaron Francis:** This is true up until the time of recording, and I don't think there are any plans to fix this as of yet. This column is four bytes, and it stops at 2038. As of MySQL 8.0.28, they did fix some of the functions that work with timestamps to allow broader ranges, but the column itself still doesn't work.

**Aaron Francis:** Let me show you these functions. So here we are in MySQL 8.0.27, and if we were to say select UNIX timestamp, we can pass in a date, and that will tell us the number of seconds since the epoch. So we'll say 2038-01-01, and we'll just run it that way. And so we get this huge, massive number of seconds since the epoch. Now, if we were to do something beyond what the timestamp column can support, 2038, we get, wah, wah, we get zero.

**Aaron Francis:** And that's of, that's as of 8.0.27. If we were to open another connection that is on 8.0.28 and we were to run that over here, we'd see that we do get the correct value. So those functions have been updated, but the column type is still bound to four bytes, which ends at 2038.

**Aaron Francis:** Now that we know that this problem exists and we've kind of proven how it manifests itself, the question is, what do you do? What do you do about this problem? How do you work around it? My first suggestion would be try to retire. Try to make it somebody else's problem. That's what I'm trying to do. I got 15 years to get out of the game. I think I can do it. I need you to like and subscribe so that I can get out earlier.

**Aaron Francis:** But here's, here's why I don't think it'll be a problem until 2038. If you only store values that are, uh, events or, like, point-in-time values like created at, updated at, modified, deleted, archived, all of those, um, point-in-time references, you're not gonna be storing values that are far in the future.

**Aaron Francis:** You are recording when something happened, and so it's not gonna be a problem until you hit 2038. So what I would say is don't use a timestamp column to store far future values because then you can get in trouble a lot earlier, right? So if you have a, if you have a column where the user can input a value ten or twenty years out, you, you could get in trouble in the next year or two, right?

**Aaron Francis:** You could get in trouble now. So my recommendation would be only store a-as of right now or earlier values in the timestamp, and you can put it off, honestly, for another fifteen years. The second option would be to switch to date time, and then your range just explodes. You have up to the year 9999, which should cover your use cases.

**Aaron Francis:** So that would be, that would be my other recommendation. If you do need to store far future values, switch to a date time. There is a little bit of a difference between how a timestamp and a date time treat time zones, and it's pretty important that we talk about it, so let me show you back in that epochs table. Let's just select the first row because that's the one where they both match.

**Aaron Francis:** So we've got 2038-01-01, zeros all the way out in both columns. Now- The way that MySQL treats a timestamp column is whenever you put a value in, it tries to help you out. It's not, it's not very helpful. It tries to help you out by converting that value to UTC. And then when you read that value back out, it tries to convert it to whatever your time zone is.

**Aaron Francis:** And that can be really surprising. With a date time column, it doesn't touch time zones at all. If you put a value in, you're gonna get a value back no matter what. You're gonna get that exact same value. It'll-- it will never convert for you. So if we look at this, we'll see that we have both of them set to 00:00, right? But if I explicitly change my time zone to, to be UTC, so I'm gonna change that to UTC and read this again, you'll see that this one, the timestamp

**Aaron Francis:** changed to be six hours off because when I inserted it, my connection was set to negative six. So if I change this to negative six, which is, uh, Central Time in the United States, and then I read it back out, you'll see that it comes back out as 00. And so that's something that you have to be aware of.

**Aaron Francis:** Hopefully, your application framework or whatever you're using to connect to the database is set to UTC. But that is something that you definitely need to be aware of is, is that MySQL is gonna muck with your time zones. And if you weren't expecting it, it's gonna be pretty frustrating. The 2038 problem, the epocalypse, time zones, timestamps, date times, there's a lot to remember, right?

**Aaron Francis:** But now you know what the 2038 problem is and find your neighborhood grandpa and talk to him about Y2K, and you guys can bond over 2038 and Y2K. Kind of the same, kind of different. If you liked this, I've got a full free MySQL course. It's 64 videos, seven and a half hours long, and it's just me talking about MySQL the entire time.

**Aaron Francis:** You can find that at planetscale.com/mysql. If you don't wanna go over there, stay tuned to this channel. We're gonna be putting out videos every couple of days. And I read every single comment. So if you get a, a funny reply, it's from me. If you get a lame reply, it's probably from somebody else. But I read every single comment, so please leave a comment.

**Aaron Francis:** Tell me what you liked, what you also liked, um, and what you wanna see next. And hopefully I'll talk to you in a few days. See ya.

---

## Related on aaronfrancis.com

- [Do The Hardest Thing with Jesse Hanley](/podcast/do-the-hardest-thing-with-jesse-hanley-9b42d310) *(Podcast · 2026-05-26 · shared: planetscale, mysql)*
- [Bury The Hatchet](/podcast/bury-the-hatchet-8ee6484d) *(Podcast · 2025-09-23 · shared: planetscale, mysql)*
- [Making videos developers actually want to watch](/podcast/making-videos-developers-actually-want-to-watch-6e3ad549) *(Podcast · 2024-06-03 · shared: mysql, planetscale)*
- [The Layoff](/podcast/the-layoff-78504819) *(Podcast · 2024-03-12 · shared: planetscale, mysql)*
- [It's Content, Baby!](/podcast/its-content-baby-fa50787e) *(Podcast · 2024-01-11 · shared: mysql, planetscale)*

## Relevant Resources from Aaron Francis

- **[MySQL for Developers](https://databaseschool.com)** (overview on site: [/courses](/courses)): Full video course covering MySQL indexing, deferred joins, pagination, query plans, and schema design for application developers.
- **[Mastering Postgres](https://databaseschool.com)** (overview on site: [/courses](/courses)): Deep-dive video course on PostgreSQL indexing, query performance, JSONB, full-text search, locking, and production operations.

## Search aaronfrancis.com (2-Hop Static Keyword Index)

Pick the alphabetical shard matching any topic to find exact pages across all articles, newsletters, videos, talks, and podcast transcripts (every shard is < 40 KB):
[A-B](/llms/keywords/a-b.txt) · [C](/llms/keywords/c.txt) · [D-E](/llms/keywords/d-e.txt) · [F-G](/llms/keywords/f-g.txt) · [H-J](/llms/keywords/h-j.txt) · [K-L](/llms/keywords/k-l.txt) · [M-N](/llms/keywords/m-n.txt) · [O-P](/llms/keywords/o-p.txt) · [Q-R](/llms/keywords/q-r.txt) · [S](/llms/keywords/s.txt) · [T-Z](/llms/keywords/t-z.txt) · [Directory](/llms/keywords.txt) · [Site Map](/llms.txt)

Shards for this page's topics: `mysql` ([M-N](/llms/keywords/m-n.txt)), `timestamp` ([T-Z](/llms/keywords/t-z.txt)), `datetime` ([D-E](/llms/keywords/d-e.txt)), `planetscale` ([O-P](/llms/keywords/o-p.txt)).

## About Aaron Francis (Current Context)

Aaron Francis is VP of Marketing and Community at [Laravel](https://laravel.com), founder of [Try Hard Studios](https://tryhardstudios.com), creator of [Solo](https://soloterm.com), co-host of [Mostly Technical](/podcast), and author of [Mastering Postgres](/courses), [High Performance SQLite](/courses), [MySQL for Developers](/courses), and [Screencasting.com](/courses). Full bio: [/about](/about) · Current focus: [/now](/now).
