Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

convert string to_date /time

Status
Not open for further replies.

annemie

Programmer
Nov 22, 2002
7
BE
Hello,

I have a log in the database witch keeps in one colum the starttime of one activity end in an other the endtime
So : activity|starttime|endtime

I like to subtract these and make the sum off all hours dedicated to one activity

SELECT SUM(DATEDIFF(hour,Starttime,stoptime)) AS Expr1
FROM dbo.Projectlog

But i have got this database where de datatype for Startime and Stoptime is nvarchar(50)
example for a cell in starttime/stoptime: 8:56:01 AM

How do i convert this so i can use it to calaculate the datediff as above ?

Annemie
 
Use the Cast or Convert function.

Convert(datetime, StartDate)
Cast(StartTime As datetime)

SELECT
SUM(DATEDIFF(hour,
Cast(StartTime As datetime),
Cast(StopTime As datetime))) AS HoursDiff
FROM dbo.Projectlog
Terry L. Broadbent - DBA
Computing Links:
faq183-874 contains "Suggestions for Getting Quick and Appropriate Answers" to your questions.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top