Solved

timespan

Posted on 2009-05-15
9
436 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
  • 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
Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
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

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Introduction When many people think of the WebBrowser (http://msdn.microsoft.com/en-us/library/2te2y1x6%28v=VS.85%29.aspx) control, they immediately think of a control which allows the viewing and navigation of web pages. While this is true, it's a…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

830 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