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. |