Click here to Skip to main content
15,899,314 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi friends,

I have a table in database which contains three columns :

1. start with datatype datetime
2. end with datatype datetime
3. and the third column difference,

Now what I want is the difference should show the difference of other two columns in days hours min sec



What should I do so that whenever I write query select * from [tableName] difference show the difference of other 2 column.


thanks
Posted
Updated 13-Oct-10 0:08am
v2
Comments
Sandeep Mewara 13-Oct-10 5:50am    
Violation of 3-NF!
Dalek Dave 13-Oct-10 6:08am    
Edited for Grammar and Spelling.

Various ways to do this discussed here[^].

You can choose whichever method suits your requirement.
 
Share this answer
 
Comments
dahras 13-Oct-10 6:18am    
thanks
Why do you need the third column? cannot you use the DATEDIFF[^] function in your query?

:)
 
Share this answer
 
Comments
Dalek Dave 13-Oct-10 6:08am    
Good Call Carlo.
dahras 13-Oct-10 6:18am    
thanks plz have a look at next answer thanks
Let me know that u want to get difference of dates in datetime or no of days.if no of days. u can choose
select DATEDIFF(day,GETDATE(),GETDATE()+1)
 
Share this answer
 
Comments
dahras 13-Oct-10 6:30am    
i wanna get the dates from the column value. but how ?
Mohd Wasif 13-Oct-10 6:50am    
how u are inserting date difference in third column, i don't think there should be use of 3 column.
thanks pallini,

VB
DATEDIFF (datepart ,startdate ,enddate )



but the startdate and enddate are contained as column value and i have to calculate the time difference in each row.

i have a query:

SQL
DECLARE @INT INT

SET @INT = DATEDIFF(SECOND,GETDATE(),GETDATE()+1)

select
convert(varchar(10), (@INT/86400)) + ':' +
convert(varchar(10), ((@INT%86400)/3600)) + ':'+
convert(varchar(10), (((@INT%86400)%3600)/60)) + ':'+
convert(varchar(10), (((@INT%86400)%3600)%60)) as 'DD:HH:MM:SS'


how can i add the value of colums so that it could display me the time difference of complete table.


thanks
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900