-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 6 posts ] 
Author Message
 Post subject: Store time, best way
PostPosted: Tue Jan 16, 2007 10:09 am 
Newbie

Joined: Tue Jan 16, 2007 7:34 am
Posts: 9
Hi

I need to store time in my DB. I wonder which is the best or recommended way to do it.

Should I use timestamps ? Should I use a String representation in a varchar ?

I will need to make searches with comparisons with this field so speed for that is important.

Thanks in advance

C


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jan 16, 2007 12:12 pm 
Newbie

Joined: Tue Jan 16, 2007 8:58 am
Posts: 17
I don't know which database you are using, but I would recommend using timestamp. You can very easily do comparisons on dates and most databases are optimized to manage them.

Using varchar representations can also lead into other issues such as formatting (dd/MM/yyyy or MM/dd/yyyy for example).


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jan 16, 2007 12:17 pm 
Newbie

Joined: Tue Jan 16, 2007 7:34 am
Posts: 9
mariec wrote:
I don't know which database you are using, but I would recommend using timestamp. You can very easily do comparisons on dates and most databases are optimized to manage them.

Using varchar representations can also lead into other issues such as formatting (dd/MM/yyyy or MM/dd/yyyy for example).


Thanks for your reply.

I'm talking about time and not date. I just one to store an init time and a finish time for some process and I don't mind about date.

To be clear, If I do it with varchars I'll store 20:35 and not 12/20/2006 20:35.

any idea ?

Thanks in advance

C


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jan 16, 2007 12:32 pm 
Newbie

Joined: Tue Jan 16, 2007 8:58 am
Posts: 17
I'd still use datetime (timestamp) fields. Of course, some databases offer only time fields and some don't. Depending on the DB, the choice can be different. If you could specify the db I could give you a better answer


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jan 16, 2007 1:16 pm 
Newbie

Joined: Tue Jan 16, 2007 7:34 am
Posts: 9
mariec wrote:
I'd still use datetime (timestamp) fields. Of course, some databases offer only time fields and some don't. Depending on the DB, the choice can be different. If you could specify the db I could give you a better answer


MySQL.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jan 19, 2007 3:03 am 
Newbie

Joined: Tue Jan 16, 2007 8:58 am
Posts: 17
In MySQL there is a TIME data type. MySQL offers various functions to do date and time comparisons

Here are some more details for MySQL 5

http://www.databasejournal.com/features/mysql/article.php/3577131


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 6 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.