Connecting Tech Pros Worldwide Forums | Help | Site Map

best MySQL field type for Unix timestamp?

kingofkolt
Guest
 
Posts: n/a
#1: Jul 17 '05
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



Andy Hassall
Guest
 
Posts: n/a
#2: Jul 17 '05

re: best MySQL field type for Unix timestamp?


On Sun, 01 Aug 2004 04:22:08 GMT, "kingofkolt" <jessepNOSPAM@comcast.net>
wrote:
[color=blue]
>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.[/color]

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 <andy@andyh.co.uk> / Space: disk usage analysis tool
http://www.andyh.co.uk / http://www.andyhsoftware.co.uk/space
Hello World
Guest
 
Posts: n/a
#3: Jul 17 '05

re: best MySQL field type for Unix timestamp?


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

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
:-)
Geoff Berrow
Guest
 
Posts: n/a
#4: Jul 17 '05

re: best MySQL field type for Unix timestamp?


I noticed that Message-ID: <Qd_Oc.193143$%_6.131400@attbi_s01> from
kingofkolt contained the following:
[color=blue]
>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.[/color]

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/
Closed Thread