473,386 Members | 1,699 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

(datediff(ss,,) / 60) rounding down the minute

Hi,

I have (2) CMD statements that are used to log when a table starts loading in the database with our automated BCP process and another that will log when it completes and determine the duration between.

But...I'm having problems using datediff() to convert the duration calculated in seconds to minutes.

Here's the code snippet used to create the 1st log record:

update TABLE_LOAD_TRACKING
set last_load_start=getdate(),
last_load_end = null,
load_duration = null,
num_rec= 0,
last_updated_by='LOADING'
where table_nm= 'TABLE_A'

This creates a log record like:

table_nm: TABLE_A
last_load_start: 9:59:40 AM
last_load_end: null
load_duration: null
num_rec: 0
last_updated_by: LOADING

Then...when the load is complete another CMD file updates that record to log the endtime and duration.

Here's the code snippet:

update TABLE_LOAD_TRACKING
set last_load_end=getdate(),
load_duration = datediff(ss, last_load_start, getdate()) / 60 ,
num_rec=(select count(*) from TABLE_A),
last_updated_by='COMPLETE'
where table_nm= 'TABLE_A'

...which results in the record now saying:

table_nm: TABLE_A
last_load_start: 9:59:40 AM
last_load_end: 10:01:14 AM
load_duration: 1.0
num_rec: 267916
last_updated_by: COMPLETE

Problem: load_duration should show something like 1.57

My timestamp examples may be a little off, but it's boiling down to the datediff() only setting the # of full minutes that have passed, not the actual x.y number of minutes that have passed.

I've tried playing around with the format of the load_duration field, but with no luck so far. My current setting for that field is: decimal, precision 18, scale 2

Any suggestions or insight are appreciated!!

Thanks!

--Andrea S.
SQL Server 2000
Oct 13 '06 #1
5 9190
Hi,

Just to clarify...

I meant to say that the calculation of:
datediff() / 60
is not returning the result as I'd expect of x.y....it's returning in x.0

Thanks!
Oct 13 '06 #2
Hi again,

Ok, I was able to resolve the problem. Here's the solution for anyone else who may come across this...



My original snippet from the update statement to convert seconds to minutes was:
load_duration = datediff(ss, last_load_start, getdate()) / 60


Let's say the duration was 2.73 minutes. The above would only return 2.0 minutes.




When I change the statement to:
load_duration = datediff(ss, last_load_start, getdate()) / 60.0


...it now results in 2.73


Kind of strange that the whole purpose of me dividing the seconds by 60 to get minutes still resulted in the # of full minutes. It looks like SQL Server needs to be told to return the partial also.

HTH someone in the future.

Take care,

--Andrea S.
Oct 13 '06 #3
Thanks for posting your solution
Oct 13 '10 #4
ck9663
2,878 Expert 2GB
This has something to do with data type precedence and the how the division operator works.

If the dividend and the divisor are of different data type, the whole operations returns the data type of the argument with the highest precedence.

If both dividend and divisor are integers, the result is integer with the fractional part truncated.

Happy Coding!!!

~~ CK
Oct 13 '10 #5
NeoPa
32,556 Expert Mod 16PB
Andrea:
Kind of strange that the whole purpose of me dividing the seconds by 60 to get minutes still resulted in the # of full minutes. It looks like SQL Server needs to be told to return the partial also.
The more usual approach is for people using SQL Server to learn how it works, rather than to expect it to try to read their minds. It's a very powerful tool if used correctly, but it was never designed to stretch quite that far.
Oct 14 '10 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Christopher T King | last post by:
Speakign of rounding errors, why is round() defined to round away from zero? I've always been quite fond of the mathematical definition of rounding of floor(n+.5). As a contrived example of why the...
4
by: spebola | last post by:
I am using vb.net 2003 professional and I get the following results when using the round method: dim Amount as decimal = 180.255 Amount = Amount.Round(Amount, 2) Amount now contains 180.25. ...
2
by: Rob Keel | last post by:
Hi, Totally new to programming and am using VB.net. Question ... I have a simple form with three text boxes ... TextBox1, TextBox2 and TextBox3. In TextBox3 I would like to return the value of...
1
by: David | last post by:
Hi, I have a report which may have calculated results fields as: 1498.13 or 964.5 I would like to know how to round up or down to 1498 or 964, or round up if over .5
5
by: Cygnus | last post by:
Sorry in advance for the lack of formatting in this posting. Data: (column headers) Net Sales | Royalty Rate | Total Royalty (data) 4.31 | 50.00% | 2.15 19.35 | 50.00% | 9.68
18
by: jdrott1 | last post by:
i'm trying to round my currency string to end in 9. it's for a pricing application. this is the function i'm using to get the item in currency: FormatCurrency(BoxCost, , , , TriState.True) if...
5
by: narpet | last post by:
Okay... here's my query: select tblPreGenTLL.RiskNumber, tblPreGenTLL., cast((tblITMmaster.ITM * (tblManuals. * .)) + ((tblITMmaster.ITM * (tblManuals. * .)) * .1526) + (.DWRFRate) + (.) +...
1
by: sjohnson1984 | last post by:
Hi all, here's a quick for which I haven't been able to track down a quick solution on Google. The 2 amounts delivered ('outgoings' and 'alreadyprotected' will always be between 0 and 9999. ...
8
by: Lewe22 | last post by:
I have 2 fields in a table called and . They are both in short time format. I am displaying these in a form with a calculated field to show the time duration as well. (ie. = -) this is also...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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,...
0
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...

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.