Reputation: 3749
Which of the method is better to insert current time in mySQL.
PHP: time()
in db column type INT(10)
or
MySQL: Now()
in db type (datetime)
Thanks.
Upvotes: 2
Views: 2441
Reputation: 1955
The second - Now in datetime. Time returns a string. You'd need datetime most likely for different time-based calculations, plus there are tons of way to retrieve and format it with your queries.
Upvotes: 2
Reputation: 19251
storing a datetime is more useful for things like finding how many days have past. you can use all of date/time mysql functions in your queries.
Upvotes: 2
Reputation: 490143
The second one is generally better as you don't need to convert it to a proper datetime before using other MySQL datetime functions on it.
Upvotes: 3