dbTalk Databases Forums  

Displaying Time as in Total amount of time

microsoft.public.sqlserver.dts microsoft.public.sqlserver.dts


Discuss Displaying Time as in Total amount of time in the microsoft.public.sqlserver.dts forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
MDPILWL
 
Posts: n/a

Default Displaying Time as in Total amount of time - 01-23-2005 , 12:57 AM






I'm not sure if this is where I post this but here it goes.

I have already imported the data from an excel file, in excel it has the
ability to display this field as the total amount of time sense the start of
the clock for example "66:21:22" is 66hrs 21mins and 22secs.

The raw number in excel is 2.76483796296088 and after importing it as a
datetime field it is displaying as "1/2/1900 6:21:22 PM"

What I need to do is display it as a result from a query as the number of
hrs mins and secs the way excel did hh:mm:ss.

thanx in advance.



Reply With Quote
  #2  
Old   
Sue Hoegemeier
 
Posts: n/a

Default Re: Displaying Time as in Total amount of time - 01-26-2005 , 03:18 PM






What is the data type of the column where you have the date
stored?
I'm not sure where or how you need to display this but one
option is if this is in a smalldatetime column you can get
the datediff from 1/1/1900 00:00:00 in seconds from the date
you have stored. Then convert the seconds to the format you
want.
Something along the lines of:

DECLARE @startdate datetime
DECLARE @enddate datetime
DECLARE @secs as integer

SET @startdate = '1/1/1900 00:00:00'
SET @enddate = '1/2/1900 6:21:22 PM'

SET @secs = datediff(ss, @startdate, @enddate)


SELECT RIGHT('00' + CAST(@secs/3600 as varchar(10)), 2)
+ ':'
+ RIGHT ('00' + CAST(@secs%3600/60 as varchar(2)),2)
+ ':'
+ RIGHT ('00' + CAST(@secs%60 as varchar(2)),2)

The above should return 42:21:22
Even though that example is based on your data type being
smalldatetime, the start and end date were set to datetime
data type so that the it doesn't round to minutes and drop
some of the seconds in the datediff function.

-Sue

On Sat, 22 Jan 2005 22:57:01 -0800, "MDPILWL"
<MDPILWL (AT) discussions (DOT) microsoft.com> wrote:

Quote:
I'm not sure if this is where I post this but here it goes.

I have already imported the data from an excel file, in excel it has the
ability to display this field as the total amount of time sense the start of
the clock for example "66:21:22" is 66hrs 21mins and 22secs.

The raw number in excel is 2.76483796296088 and after importing it as a
datetime field it is displaying as "1/2/1900 6:21:22 PM"

What I need to do is display it as a result from a query as the number of
hrs mins and secs the way excel did hh:mm:ss.

thanx in advance.



Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.