Solved

# timespan

Posted on 2009-05-15
Medium Priority
439 Views
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.
0
Question by:VBdotnet2005
[X]
###### Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

• Help others & share knowledge
• Earn cash & points
• 4
• 2
• 2
• +1

LVL 11

Expert Comment

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

dtNow is one datetime
dtyest is other datetime
0

LVL 16

Expert Comment

ID: 24398937
Slight correction:

Use the TotalHours property to get the elapsed hours.
0

Author Comment

ID: 24398943

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

LVL 16

Expert Comment

ID: 24399009
I don't know what you're asking. An elapsed time is not for any specific day.
0

Author Comment

ID: 24399065
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

LVL 16

Expert Comment

ID: 24399080
? The timespan difference.totalhours would return 2. that IS the difference!
0

LVL 11

Expert Comment

ID: 24399106
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

LVL 8

Accepted Solution

RyanAndres earned 2000 total points
ID: 24399487
This is what you want... plain and simple.
``````double totalHours = (DateTime.Now - DateTime.Parse("10:05:01 AM")).TotalHours;
``````
0

LVL 16

Expert Comment

ID: 24400812
I agree. I'm not sure what's going on here! :)
0

## Featured Post

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Well, all of us have seen the multiple EXCEL.EXE's in task manager that won't die even if you call the .close, .dispose methods. Try this method to kill any excels in memory. You can copy the kill function to create a check function and replace the …
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
###### Suggested Courses
Course of the Month10 days, 10 hours left to enroll