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
 SQL Server 2000 Forums
 SQL Server Development (2000)
 Formatting datetime to hours

Author  Topic 

AskSQLTeam
Ask SQLTeam Question

0 Posts

Posted - 2002-05-30 : 09:44:08
osbert writes "how can i create a view which outputs a column with a hh:mm format?

example:
SELECT (End_dateTime-Start_DateTime) AS ElapsedTime FROM Table1;

the ElapsedTime column should display the total hours and minutes (hh:mm) from the expession given.

like:
if
Start_datetime = 05/28/2002 08:00:00 AM
End_datetime = 05/29/2002 09:20:00 AM
then
ElapsedTime = 25:20"

Page47
Master Smack Fu Yak Hacker

2878 Posts

Posted - 2002-05-30 : 09:51:56
take a look at datediff and datepart in books on line

<O>
Go to Top of Page

mopdam
Starting Member

1 Post

Posted - 2002-05-30 : 10:01:50
quote:

TRY

SELECT CAST(DateDiff(mi, Start_DateTime, End_dateTime)/60 As NVarChar) + ':'+ Right('0'+CAST(DateDiff (mi, Start_DateTime , End_dateTime)%60 As NVarChar),2) AS ElapsedTime
FROM Table1




Go to Top of Page
   

- Advertisement -