Solved

timespan

Posted on 2009-05-15
9
438 Views
Last Modified: 2012-05-07
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
Comment
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
  • Learn & ask questions
  • 4
  • 2
  • 2
  • +1
9 Comments
 
LVL 11

Expert Comment

by:srikanthreddyn143
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

by:ToddBeaulieu
ID: 24398937
Slight correction:

Use the TotalHours property to get the elapsed hours.
0
 

Author Comment

by:VBdotnet2005
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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 16

Expert Comment

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

Author Comment

by:VBdotnet2005
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

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

Expert Comment

by:srikanthreddyn143
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

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

Open in new window

0
 
LVL 16

Expert Comment

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

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

This tutorial demonstrates one way to create an application that runs without any Forms but still has a GUI presence via an Icon in the System Tray. The magic lies in Inheriting from the ApplicationContext Class and passing that to Application.Ru…
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 …
In this video, viewers will be given step by step instructions on adjusting mouse, pointer and cursor visibility in Microsoft Windows 10. The video seeks to educate those who are struggling with the new Windows 10 Graphical User Interface. Change Cu…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
Suggested Courses

615 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question