sasori
sasori

Reputation: 5445

unix time in mysql

when they say "we will use unix time", does that mean i should create a column like this ?

date DATE

or

date TIME

or

date DATETIME

?

Upvotes: 1

Views: 669

Answers (3)

nos
nos

Reputation: 229058

A unix time is just a number representing the nr of seconds since 1970. If you want to store that directly, use an INTEGER.

You're likely better off storing this as a DATETIME, as that will facilitate easier querying. Though when inserting data you might need to convert it using the from_unixtime function.

A DATE stores only the date, not the time(hour/min/secs) and a TIME stores only the time not the date so they're not suitable.

Upvotes: 3

AJ.
AJ.

Reputation: 28174

UNIX time is expressed as an integer value - number of seconds since the epoch. You'd just want to use an int field for this, not any of the date variants.

Upvotes: 1

Bobby
Bobby

Reputation: 11576

Unix-Time is normally seconds from 01-01-1970...means integer.

Upvotes: 0

Related Questions