Solved

timespan

Posted on 2009-05-15
9
433 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
 
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
Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 

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

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

I think the Typed DataTable and Typed DataSet are very good options when working with data, but I don't like auto-generated code. First, I create an Abstract Class for my DataTables Common Code.  This class Inherits from DataTable. Also, it can …
If you're writing a .NET application to connect to an Access .mdb database and use pre-existing queries that require parameters, you've come to the right place! Let's say the pre-existing query(qryCust) in Access takes a Date as a parameter and l…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

708 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

21 Experts available now in Live!

Get 1:1 Help Now