I'm saving data from a CSV file into a MySQL database. I'm using Laravel and trying to decide what is the best way to store such data. See: http://laravel.com/docs/4.2/schema#adding-columns. Do I use timestamp
? Would I lose anything if I just stored it as a string?
Asked
Active
Viewed 590 times
2

StackOverflowNewbie
- 39,403
- 111
- 277
- 441
-
3how about a `datetime` with '1900-01-01 03:54:32' going into it. Don't go the string route. You will lose all functionality of datemath functions – Drew Sep 24 '15 at 05:00
-
1Indeed mysql datetime does not have the Unix timestamps limitations. Any year from 1000 to 9999 is acceptable. – Déjà vu Sep 24 '15 at 05:01
-
Although `w3school` is not what they recommended here have a look at this link to convert to `MySQL` date format http://www.w3schools.com/sql/func_date_format.asp – usrNotFound Sep 24 '15 at 05:10
1 Answers
3
Use datetime
The advantage of datetime
over string is that it will be stored more efficiently and you will be able to query this data with more tools

Jossef Harush Kadouri
- 32,361
- 10
- 130
- 129
-
And I can store `1/01/1900 3:54:32 a.m.` as in in that column? – StackOverflowNewbie Sep 24 '15 at 05:21
-
Yes. You will need to use MySQL's [`STR_TO_DATE()`](http://dev.mysql.com/doc/en/date-and-time-functions.html#function_str-to-date). And the `a.m` is redundant – Jossef Harush Kadouri Sep 24 '15 at 05:28