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)
 Question

Author  Topic 

AskSQLTeam
Ask SQLTeam Question

0 Posts

Posted - 2005-08-15 : 07:33:46
ch suresh writes "to find the difference between a column and other
both are of Char datatype and store the time value in it.
i do want to find out the time consumed i.e the difference between the columns which are of char datatype.
tell me how can i find the difference in time of a char datatype columns.


tell me how to convert the char datatype to other in sql server say i want to convert it to the datetime if i convert to the datetime datatype it is taking the default as some where around 1900 but i only want to store the column with the timevalue"

timmy
Master Smack Fu Yak Hacker

1242 Posts

Posted - 2005-08-15 : 07:37:40
To convert a column to datetime, you can use the CAST or CONVERT functions:
DECLARE @myTimeCh char(10)
DECLARE @myTime datetime
SET @myTimeCh = '11:00:00'
SET @myTime = CONVERT(datetime, @myTimeCh)

Then you can use the DATEDIFF function to tell the difference between them:
DATEDIFF(n, CONVERT(datetime, @timeCh1), CONVERT(datetime, @timeCh2))

Look up CAST, CONVERT and DATEDIFF in Books Online for more info.

Tim
Go to Top of Page
   

- Advertisement -