Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Is There a way to return a float value from a DATEDIFF function in a Stored Procedure?

1,190 views
Skip to first unread message

Edward Carrigan III

unread,
Apr 10, 2001, 4:53:15 PM4/10/01
to
I need the float value of this, and not the integer.
SET @totalHours = DATEDIFF(hour, @startTime, @lunchOut) + DATEDIFF(hour,
@lunchIn, @endTime)

Any help would be great!!(I'm a newbie)


Matt Pavey

unread,
Apr 10, 2001, 5:05:33 PM4/10/01
to
maybe try using the convert function to convert the result to what you need

hope that helps..

"Edward Carrigan III" <edw...@enthusiasm.com> wrote in message
news:3ad37...@news.nwlink.com...

Matt Pavey

unread,
Apr 10, 2001, 5:09:44 PM4/10/01
to
this worked

declare @startdate datetime,
@enddate datetime

set @startdate = getdate()
set @enddate = getdate()-7

select @startdate
select @enddate

select convert(float,datediff(hour,@enddate,@startdate))

it returns 168 without the convert, but with convert returns 168.0


That help??

"Matt Pavey" <mpa...@ind.tds.net> wrote in message
news:#4y4yDgwAHA.1432@tkmsftngp02...

Tobias Thernström

unread,
Apr 10, 2001, 5:17:54 PM4/10/01
to
Edward,

Are you sure you would like a value of the datatype float, it is approximate
and will not
allways return the value you expect. It seems you would be better of with
decimal if
you will be needing decimals in your value.

/Tobias
SQL Server MCT

* Please post replies to the newsgroup *

"Edward Carrigan III" <edw...@enthusiasm.com> wrote in message
news:3ad37...@news.nwlink.com...

Fabio Luiz Ide

unread,
Apr 10, 2001, 5:17:22 PM4/10/01
to
I dont know if this answers your question, but if you execute

SET @totalHours = 1.0 * DATEDIFF(minute, @startTime, @lunchOut) / 60 +
1.0 * DATEDIFF(minute, @lunchIn, @endTime) / 60

Or


SET @totalHours = 1.0 * ( DATEDIFF(minute, @startTime, @lunchOut) +
DATEDIFF(minute, @lunchIn, endTime) ) / 60

you will be able to get fractions of an hour.


[]s

Fabio Ide


"Edward Carrigan III" <edw...@enthusiasm.com> escreveu na mensagem
news:3ad37...@news.nwlink.com...

Edward Carrigan III

unread,
Apr 10, 2001, 5:31:19 PM4/10/01
to
Thanks Fabio,

Works beautifully!!!

Ed

"Fabio Luiz Ide" <fabi...@directtalk.com.br> wrote in message
news:ON$WYOgwAHA.1844@tkmsftngp05...

0 new messages