28

Should I use DATETEIME? or INT?

Thanks!

EDIT: I'm specifically addressing the

public static $timestamps = true;

flag set in Eloquent models.

brennanag
  • 583
  • 1
  • 5
  • 12
  • 1
    Yes. No? Perhaps. Definitely. Are you storing dates, or are you storing integers? With the answer to _that_ question, _your_ question is solved. – Bojangles Sep 06 '12 at 08:36
  • Laravel offers the option to automatically take care of this with this variable set in the model : public static $timestamps = true; I'm trying to construct my tables to support this. – brennanag Sep 06 '12 at 08:38
  • @JamWaffles Would you consider removing your downvote? Or explain it? – brennanag Sep 06 '12 at 08:45
  • 1
    Gave you an upvote since this question is not as lame as JamWaffles answer sounds. There are different applications that use the unix timestamp for this. I don't wanna say whats good or bad about it, but they exist and so one should be allowed to question about. – Del Pedro Sep 06 '12 at 09:15
  • Thanks. This isn't a question about what is best/worse/right/wrong, it's just a question about what the framework uses, seeing as I couldn't easily find it by googling or looking in the documentation. – brennanag Sep 06 '12 at 09:23

3 Answers3

27

Laravel only supports datetime for their timestamps.

https://github.com/laravel/laravel/pull/769

Jürgen Paul
  • 14,299
  • 26
  • 93
  • 133
  • 1
    check the pull request I linked as well ;) – Jürgen Paul Sep 06 '12 at 08:46
  • 4
    I think it is downvoted because it is not as question which you can answer yourself with a look in laravel's well documented code. So, if you look inside laravel/database/eloquent/model.php and search for timestamp you will see, that there is a public function called timestamp(). Inside this function you will see that $this->updated_at is set with new \DateTime; So it is ever a good practice first to view if you can handle it by yourself. – Dirk Sep 17 '12 at 10:13
7

Just as an update: Mich's answer is still valid for Laravel 3 and below,

but as of Laravel 4, it switched to supporting timestamp columns for created_at and updated_at.

Here's a related issue on GitHub

Community
  • 1
  • 1
FireSBurnsmuP
  • 923
  • 10
  • 28
5

Laravel 5 defaults is TIMESTAMP

Stanislav
  • 923
  • 1
  • 11
  • 28