Roman
Roman

Reputation: 3749

Insert current time with NOW() or TIME()

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

Answers (3)

AR.
AR.

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

dqhendricks
dqhendricks

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

alex
alex

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

Related Questions