Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Development Tools

MySQL bug: timestamps older than 45 years (from today) aren't being committed

I'm in laravel 4.2 using Carbon

Is this even a bug or my lack of understanding of MySQL? On one table I'm working with three timestamp columns. All the way up to persistence (being saved) in the database, the object is populated with the desired timestamp. I've checked it right up until the save command is called and it's all fine!

But when it gets entered into the database, the timestamps show as 000-00-00 00:00:00. I mean.. what! It only happens to timestamps 45 years in the past from today. All the logic for dates within the past 45 years works fine.

Is this on purpose? Or a big? Or a setting? AGH!

How are you inserting the timestamps into the database? Looks to me like you ran into a Unix time issue.

2 Answers

Milo Winningham
seal-mask
.a{fill-rule:evenodd;}techdegree
Milo Winningham
Web Development Techdegree Student 3,317 Points

The MySQL TIMESTAMP type is a Unix timestamp (defined as the time since January 1, 1970). To store a date before that, you'll have to use the DATETIME type instead. More information here: http://dev.mysql.com/doc/refman/5.5/en/datetime.html

It was 4am after posting this that It hit me - what am I using? A Timestamp. What year was roughly 45 years ago? 1970. Aggghhhhhh.

I'm submitting to a format of Y-m-d H:i:s (I think that's correct), so I'm hoping all I need to do is write a migration to change the field type.

Thanks guys!