Solved

timespan

Posted on 2009-05-15
9
435 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
Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

 
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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

This article explains how to create and use a custom WaterMark textbox class.  The custom WaterMark textbox class allows you to set the WaterMark Background Color and WaterMark text at design time.   IMAGE OF WATERMARKS STEPS Create VB …
It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…

813 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now