7
Answers

Prob In Time Duration ?

suren v

suren v

11y
893
1
Hai, Frnds,

               I have problem to find the exact time duration . Like this ---> I have {From time} and {To time} two fields in table in SQL server 2008 database. In this how should i find exact duration of this Time....? ? ? 


Table:
--------
From Time         To Time                Duration 
01:05:10 Pm    02:05:10 Pm          01:00:00 




Thanks In Advance :)
Answers (7)
0
Iftikar Hussain

Iftikar Hussain

NA 18.9k 275.4k 11y
try like this


declare @time1  varchar(20)
declare @time2  varchar(20)

set @time1='01:05:10 Pm'
set @time2='02:15:11 Pm'
select convert(varchar,CAST(@time2 as datetime)-CAST(@time1 as datetime),108) as Diff

Regards,
Iftikar
Accepted
0
suren v

suren v

NA 113 33.1k 11y
Hai,Iftikar Hussain,


    Hai dude i found solution....Thanks for your code...it really works Good:)
0
Iftikar Hussain

Iftikar Hussain

NA 18.9k 275.4k 11y
what result you are getting? Can you share your code?

Regards,
Iftikar
0
suren v

suren v

NA 113 33.1k 11y
Hai, Iftikar Hussain Dude,


 It's not working dude.... 


Thanks for your reply :)
0
suren v

suren v

NA 113 33.1k 11y
Hai, Iftikar Hussain,

           Yes,I'm looking in sql only,.....



0
Iftikar Hussain

Iftikar Hussain

NA 18.9k 275.4k 11y
Hi,
        Are you looking for in SQL?

Regards,
Iftikar
0
nishant ranjan

nishant ranjan

NA 415 0 11y
try this

DateTime startTime =Convert.ToDateTime( "01:05:10 Pm");

DateTime endTime =Convert.ToDateTime( " 02:05:10 Pm");

TimeSpan span = endTime.Subtract(startTime);
Response.Write("Time Difference : " + span);