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.
VBdotnet2005Asked:
Who is Participating?

Improve company productivity with a Business Account.Sign Up

x
 
RyanAndresConnect With a Mentor Commented:
This is what you want... plain and simple.
double totalHours = (DateTime.Now - DateTime.Parse("10:05:01 AM")).TotalHours;

Open in new window

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

dtNow is one datetime
dtyest is other datetime
0
 
ToddBeaulieuCommented:
Slight correction:

Use the TotalHours property to get the elapsed hours.
0
Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

 
VBdotnet2005Author Commented:

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  ????
0
 
ToddBeaulieuCommented:
I don't know what you're asking. An elapsed time is not for any specific day.
0
 
VBdotnet2005Author Commented:
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?
0
 
ToddBeaulieuCommented:
? The timespan difference.totalhours would return 2. that IS the difference!
0
 
srikanthreddyn143Commented:
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)
0
 
ToddBeaulieuCommented:
I agree. I'm not sure what's going on here! :)
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.