473,748 Members | 3,604 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

What is the right datatype to store Hours up to the minute precision?

Right now the database I am working with is storing time in
an Integer data type and is storing the time value in seconds.
The application does not allow entering seconds. It accepts
minutes and hours.

I have a report where it is doing:

SELECT SUM(TIMEENTERED )

and the SUM is *blowing* up as the SUM is reaching
the BIGINT range.

I can fix the problem by changing all codes to:

SELECT SUM(CAST(TIMEEN TERED AS BIGINT))

But now that I ran into this problem I want to find out
if storing the time in seconds using INTEGER data
type is the best solution?

I've been searching this newsgroup and other places
the whole day. I even ran into my own three year old
post. Three years ago my problem was data migration
related and now it is more of performance related than
anything else.

http://groups.google.com/groups?as_q...=2006&safe=off

I could not find this specific topic in SQL books like
SQL for Smarties 2005 by Joe Celko (very good stuff on
temporal topics but nothing specific to my question),
or Inside SQL Server 2000.

Which data type would be ideal and why?

smalldatetime?
integer?
decimal?
float?

The type of operations that are being done in the database
are:

1- Entering time in hours on work done on a task
For the data entry part, the application accepts
2.5 as 2 and a half hours and it is storing
2.5 * 3600 = 9000 seconds.
It also accepts entering 2:30 as 2 hours and
30 minutes and again storing 9000 seconds.
I even saw a page where you can enter clock
time: I worked from 9:30AM to 12:45PM
as an example

When i checked the underlying table(s) I saw
that the ENTEREDTIME is always the duration
in seconds. So the data entry can either be

2.5 hours where ENTEREDTIME = 9000 seconds
or
9:00AM to 11:30AM
where STARTDATE is today's date for example
stored as 1/27/2005 09:00AM
and where ENTEREDTIME = 9000 seconds
2- All kinds of reports showing total time in hours
for example: Project1 = 18.5 hours
The code in the SP are all like:
SUM(ENTEREDTIME ) / CAST(3600 AS DECIMAL(6,2))
AS TOTALTIME

3- I am sure a lot of other arithmetic calculations are
being done with this ENTEREDTIME field.

What would be the best way to store hours/minutes
based on how we are using Time in the database?

Either I will stick with Integer but store in minutes
time instead of calculating in seconds and most likely
update all the SUM(ENTEREDTIME ) to
SUM(CAST(ENTERE DTIME AS BIGINT))
or I will switch to storing in decimal/float and
maybe avoid doing :

SUM(ENTEREDTIME ) / CAST(3600 AS DECIMAL(6,2))
AS TOTALTIME

since the ENTEREDTIME would already be stored
in hours time.
or I will use DATETIME since in the cases of

I worked from 9:00AM to 11:30AM

I have to have a separate column to store the date also.

I am a little confused I am hoping I will get some help
from you and maybe if I can't find the best solution, at
least eliminate the NOT so good ones I am thinking of.
Thank you
Jan 28 '06 #1
1 7439
serge (se****@nospam. ehmail.com) writes:
What would be the best way to store hours/minutes
based on how we are using Time in the database?

Either I will stick with Integer but store in minutes
time instead of calculating in seconds and most likely
update all the SUM(ENTEREDTIME ) to
SUM(CAST(ENTERE DTIME AS BIGINT))


Since you appear to have an application that is working, I would do
as little change as possible.

Storing elapsed time as minutes rather than seconds makes sense if you are
not supporting seconds anyway. Then again, do the potential seconds
cause any menace?

Of course, if you store by minutes you may not need bigint, but that
depends on what that sum(enteredtime ) reflects. If you store by minutes,
you need 4085 years for an overflow, which is a lot for a single person. But
if the sum encompasses a workforce of 20000 employeess, it only takes
74 days per person to overflow.

Had we been talking about a new application, I can't say for sure what
I would recommend. All the datatypes have their tradeoffs. But keep in
mind that it's possible to have computed columns, so you could have
both a smalldatetime column and a minutes column if you like.

--
Erland Sommarskog, SQL Server MVP, es****@sommarsk og.se

Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/pro...ads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodinf...ons/books.mspx
Jan 28 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
1413
by: Arne | last post by:
How do I pass a dataset to a webservices? I need to submit a shoppingcart from a pocket PC to a webservice. What is the right datatype? II have tried dataset as a datatype, but I can't get it to compile. <WebMethod()> _ Public Function VerifySku(ByVal skus As XmlDataDocument) As DataSet Test program : Dim cartSet As DataSet cartSet = ws.VerifySku(cartSet)
4
10473
by: Dabbler | last post by:
Not sure what SQL datatype should be used with radiobuttons since MS SQL doesn't support a boolean datatype. I would like to bind radiobuttons to an SqlDataSource. Thanks for any suggestions on this.
0
1219
by: graju80 | last post by:
I am kind of new to Db2... Question: What are the rules that DB2 uses to determine the right datatype for a particular column for on-the-fly SQL generation? For example...
4
1600
by: Jess | last post by:
Hello, I'm doing some calculations with great amount of precisions required. Can somebody please suggest some suitable libraries or classes to use? Thanks, Jess
4
22114
by: brazil.mg.marcus.vinicius.lima | last post by:
Hello, I need to create a column that will store hours bigger than 24. For example '25:00:00', '129:23:12', etc). That column will be used too, for perform calculations between datetime intervals: 'time'. In MySQL there is a datatype that perfect fits that necessity. Does anyone know what is the corresponding datatype in SQL Server?
1
1940
by: Nathan Sokalski | last post by:
When a DataTable is filled using something such as a DataAdapter, what values are assigned to each of the DataColumns' DataType property for the different SQL types? Thanks. -- Nathan Sokalski njsokalski@hotmail.com http://www.nathansokalski.com/
2
2835
by: =?Utf-8?B?Q2xhdWRl?= | last post by:
How can I get the complet schema of a datacolumn using ADO.Net objects (the equivalent of ADOX in ADO 2.8) ? I need to know the DataType, the DataSize, the Precision... The DataColumn object only gives DataType. Thanks, Claude
8
1458
by: ganesh22 | last post by:
Hi, in my database i gave a datatype as float so i entered a value as 3.10 but it taking as 3.1 and also i entered as 3.999 but it will taking as 4 how its possible which datatype store the actuall value ex : if i entered as 3.999 means it will as 3.999 only again if i given as 3.10 means it will take as 3.10 only
1
3353
by: djminus1 | last post by:
Hi, I am struggling to find a methodology for formatting the store hours for a restaurant that I am developing a simple CMS for. I am using codeIgniter, but it's sort of irrelevant. Basically, the restaurant owner has a page in his administration section where they can enter their store hours into a form. These hours are stored as timestamps in MySQL. What I want is to format the store hours like they are typically displayed on...
0
8991
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8830
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9544
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9372
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9324
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8243
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
4606
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3313
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2215
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.