Monday, March 26, 2012

newbie question

I have two datetimes dt1, dt2. dt2 is always greater than dt1
I want to do: dt2-dt1 and the result has to be written in the hh:mm:ss forma
t
Could anybody help me?Try,
declare @.dt1 datetime, @.dt2 datetime
declare @.i int
set @.dt1 = '2005-08-17T08:35:45.000'
set @.dt2 = getdate()
set @.i = datediff(second, @.dt1, @.dt2)
select
(@.i / 3600) as hh,
((@.i / 60) - ((@.i / 3600) * 60)) as mm,
@.i % 60 as ss
go
AMB
"DAMAR" wrote:

> I have two datetimes dt1, dt2. dt2 is always greater than dt1
> I want to do: dt2-dt1 and the result has to be written in the hh:mm:ss for
mat
> Could anybody help me?|||Hi
To get the time format u need to:
select convert(varchar(8), dt2-dt1, 108)
please let me know if this works
best Regards,
Chandra
http://chanduas.blogspot.com/
http://www.SQLResource.com/
---
"DAMAR" wrote:

> I have two datetimes dt1, dt2. dt2 is always greater than dt1
> I want to do: dt2-dt1 and the result has to be written in the hh:mm:ss for
mat
> Could anybody help me?|||DECLARE @.d1 DATETIME, @.d2 DATETIME, @.sd INT
SET @.d1 = '20050812 05:32:45'
SET @.d2 = '20050817 02:15:46'
SET @.sd = DATEDIFF(SECOND, @.d1, @.d2)
SELECT RTRIM(@.sd/3600) + ':'
+ RIGHT('0'+RTRIM((@.sd % 3600) / 60),2)
+ ':' + RIGHT('0'+RTRIM((@.sd % 3600) % 60),2)
116:43:01
Note that this doesn't know whether one of the values is in an observed time
change, e.g. summer time or daylight savings time, so has the potential to
be an hour off if it crosses one of those boundaries.
"DAMAR" <DAMAR@.discussions.microsoft.com> wrote in message
news:45868E66-C51F-4F3B-9BCA-F97D6C6827CA@.microsoft.com...
>I have two datetimes dt1, dt2. dt2 is always greater than dt1
> I want to do: dt2-dt1 and the result has to be written in the hh:mm:ss
> format
> Could anybody help me?|||not at all:(
but thanx
"Chandra" wrote:
> Hi
> To get the time format u need to:
> select convert(varchar(8), dt2-dt1, 108)
> please let me know if this works
>
> --
> best Regards,
> Chandra
> http://chanduas.blogspot.com/
> http://www.SQLResource.com/
> ---
>
> "DAMAR" wrote:
>

No comments:

Post a Comment