difference between 2 dates

  • Thread starter Thread starter weche
  • Start date Start date
W

weche

I would like to know how I can calculate the diference in time between 2
dates. I would input a date (before the current date) and the code would
calulate how many: weeks, days, hours, minutes and secondes there is between
the given date and the current date.

thanx in advance!

Lovens
 
Lovens,

For your question is the timespan structure.

http://msdn.microsoft.com/library/d.../cpref/html/frlrfsystemtimespanclasstopic.asp

And before you try to do difficult things, look at the properties and
methods from that.

As well can you look at the date and time methods in the
Microsoft.VisualBasic namespace about dates, they can be very helpfull and
although a lot of the functions in this namespace are in another way in the
standard framework, are here some which are not.

http://msdn.microsoft.com/library/d.../vblr7/html/vaorivbruntimelibrarykeywords.asp

I hope this helps,

Cor
 
weche said:
I would like to know how I can calculate the diference in time between 2
dates. I would input a date (before the current date) and the code would
calulate how many: weeks, days, hours, minutes and secondes there is
between
the given date and the current date.

\\\
Dim d1 As Date = Now
Dim d2 As Date = #4/22/1989#
MsgBox(CStr(Math.Round(d1.Subtract(d2).TotalSeconds, 0)))
MsgBox(CStr(DateDiff(DateInterval.Second, d2, d1)))
///

'DateTime.Subtract' will return a 'TimeSpan'. This structure provides
properties like 'Days', 'Minutes', 'Seconds', ...
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top