Link to home
Start Free TrialLog in
Avatar of VBdotnet2005
VBdotnet2005Flag for United States of America

asked on

timespan

how can I get the different in hr between   10:05:01 AM AND 12:25:05 PM  ? I am not sure how to use timespan.
Avatar of srikanthreddyn143
srikanthreddyn143

Dim its As TimeSpan = dtNow.Subtract(dtyest)
Dim hrs As Integer = its.Hours

dtNow is one datetime
dtyest is other datetime
Slight correction:

Use the TotalHours property to get the elapsed hours.
Avatar of VBdotnet2005

ASKER


Sorry, I forgot to ask this. How can I get just the time for today...like 12:21:01 PM


dim timenow as date = now.tostring("hh:mm:ss T")
dim time2 = 10:00:00 AM
dim ts as timespan = timenow - time2  ????
I don't know what you're asking. An elapsed time is not for any specific day.
ok in my database, I have a column which stamps time   like 10:21:01 PM only. That is what I get the value from.
now, I want to find out the different in hours from that time to the current time.

db  =  10:21:01 PM
time right now is 12:38:21 PM
result is 2 hrs. How can I get the different here?
? The timespan difference.totalhours would return 2. that IS the difference!
Try this

Dim ts As TimeSpan = New TimeSpan()
Dim ts1 As TimeSpan = TimeSpan.Parse("11:59:39")
Dim ts2 As TimeSpan = TimeSpan.Parse("12:00:05")
ts = ts2.Subtract(ts1)
ASKER CERTIFIED SOLUTION
Avatar of RyanAndres
RyanAndres
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
I agree. I'm not sure what's going on here! :)