470,833 Members | 1,410 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,833 developers. It's quick & easy.

best MySQL field type for Unix timestamp?

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
3 6269
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
> 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
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.

Similar topics

2 posts views Thread by Ben | last post: by
3 posts views Thread by Noyb | last post: by
7 posts views Thread by Tony Clarke | last post: by
9 posts views Thread by expect | last post: by
4 posts views Thread by Mark Harrison | last post: by
2 posts views Thread by hph | last post: by
6 posts views Thread by Brandon | last post: by
6 posts views Thread by Geoff Cox | last post: by
reply views Thread by mihailmihai484 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.