Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Altering the datatype of a variable?

Author  Topic 

swift
Starting Member

4 Posts

Posted - 2006-07-21 : 10:24:39
The DATEDIFF(s, time1, time2) function output is of the 'datetime' datatype.
How can I alter the 'datetime' to 'int' (or 'bigint') datatype to make it compatible with other variables in my calculations?

Srinika
Master Smack Fu Yak Hacker

1378 Posts

Posted - 2006-07-21 : 10:28:27
Give an example
What date to what integer, and if there is a logic, that as well.

eg. do u need 12/04/2006 to 12042006 ?

Srinika
Go to Top of Page

swift
Starting Member

4 Posts

Posted - 2006-07-21 : 10:52:36
It is not the issue of time FORMAT.
Here is an example. I am using DATEDIFF(s, '07/20/2006 00:00:00','07/20/2006 00:05:00'),
which returns 300 seconds.
However I cannot calculate, for example, the incoming bitrate because
dividing 100,000 bits (bigint) by seconds (datetime) is not allowed
due to different datatypes.

Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2006-07-21 : 10:56:22
datediff does not return datetime datatype but rather integer.

what is your problem with dividing 100000 by the seconds ?



KH

Go to Top of Page

Srinika
Master Smack Fu Yak Hacker

1378 Posts

Posted - 2006-07-21 : 11:01:03
Datediff returns integer

eg. Print DATEDIFF(s, '07/20/2006 00:00:00','07/20/2006 00:05:00') / 100
returns 3

Srinika
Go to Top of Page

swift
Starting Member

4 Posts

Posted - 2006-07-21 : 11:17:22
DECLARE @TimeDif AS bigint
............
SET @TimeDif = DATEDIFF (s, @TimePrev, @TimeCurr)
SET @InBitRate = (@InBitCurr - @InBitPrev)/@TimeDif

'Msg 8134, Level 16, State 1, Line 182
Divide by zero error encountered.'
Go to Top of Page

Srinika
Master Smack Fu Yak Hacker

1378 Posts

Posted - 2006-07-21 : 11:21:16
ie because ur @TimeDif = 0 in that instance
nothing to do with date data type or some such.

U may commentout the row where the dividing is taking place and put the Print TimeDif and c.
The values of @TimePrev & @TimeCurr should be same, thus making the difference in seconds to become 0.

Srinika
Go to Top of Page

swift
Starting Member

4 Posts

Posted - 2006-07-21 : 11:34:42
You are right -
I goofed with calculation of @TimePrev.
Thanks, everybody.
Go to Top of Page
   

- Advertisement -