By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,491 Members | 3,230 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,491 IT Pros & Developers. It's quick & easy.

best MySQL field type for Unix timestamp?

P: n/a
All,

What do you recommend as the best type of field for a timestamp in a MySQL
database? I've considered varchar(10) or INT but I'm not sure what is the
best, most efficient, and most reliable field type.

Thanks.

- JP
Jul 17 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
On Sun, 01 Aug 2004 04:22:08 GMT, "kingofkolt" <je**********@comcast.net>
wrote:
What do you recommend as the best type of field for a timestamp in a MySQL
database? I've considered varchar(10) or INT but I'm not sure what is the
best, most efficient, and most reliable field type.


A Unix timestamp is a 32-bit integer. Therefore, use INT.

(Personally I always stick with the database's native date datatypes, such as
DATE/DATETIME, although I can see why people might want to use Unix timestamp
in the database some circumstances).

--
Andy Hassall <an**@andyh.co.uk> / Space: disk usage analysis tool
http://www.andyh.co.uk / http://www.andyhsoftware.co.uk/space
Jul 17 '05 #2

P: n/a
> What do you recommend as the best type of field for a timestamp in a MySQL
database? I've considered varchar(10) or INT but I'm not sure what is the
best, most efficient, and most reliable field type.


What about the TIMESTAMP type ? I don't know for storage space if it
takes less/more than an int, but at least given it's a date type of
field, you can use the typical sort operation when you're retrieving
data from the database.

However note when using that type of field that the first column with
this a timestamp type will be automatically filled with the latest
time the matching line was updated, so put any valuable data only
after the first column, unlike dummies like me who didn't know about
this (stupid imho) rule and who spent days searching where was the bug
in his scripts. I mean, what's the point ? If someone wants to keep
track of when the line was updated, he can decide himself to have such
a column and use the NOW() function, duh. Ah, done with the ranting
:-)
Jul 17 '05 #3

P: n/a
I noticed that Message-ID: <Qd_Oc.193143$%_6.131400@attbi_s01> from
kingofkolt contained the following:
What do you recommend as the best type of field for a timestamp in a MySQL
database? I've considered varchar(10) or INT but I'm not sure what is the
best, most efficient, and most reliable field type.


varchar(10) is, if I'm reading the manual correctly 11 bytes. INT is 4.

--
Geoff Berrow (put thecat out to email)
It's only Usenet, no one dies.
My opinions, not the committee's, mine.
Simple RFDs http://www.ckdog.co.uk/rfdmaker/
Jul 17 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.