A date Question

  • 14 years ago

    Hello.

    I need your help with dates. I have 2 dates and i want to know the mathematical difference between them, for example:

    variable = Date1 - Date2

    Thanks

    Merovingio

  • 14 years ago

    You can use the DateDiff function to get the difference between two dates.  You'll need two date objects however. Here is an example:

            Dim firstDate As Date = Now
            Dim secondDate As Date = Now

        MsgBox(DateDiff(DateInterval.Day, firstDate, secondDate))</pre>If your dates are in the form of a string then you can convert them using date.parse. The next example demonstates this.<pre>        Dim firstdate As Date = Today
        Dim secondDate As Date = Date.Parse("12/25/2006")
    
        MsgBox(DateDiff(DateInterval.Day, firstDate, secondDate))</pre>
    
  • 14 years ago

            Dim dtOne As New DateTime(2006, 12, 1)
            Dim dtTwo As New DateTime(2006, 11, 11)

            Dim dtSpan As TimeSpan = dtOne - dtTwo

    dtSpan would give you the following values
    .TotalDays
    .TotalHours
    .TotalMilliseconds
    .TotalMinutes
    .TotalSeconds

    Cheers















  • 14 years ago
    thanks TwoFaced and  Thulasee. i did it. thank for your help.

Post a reply

Enter your message below

Sign in or Join us (it's free).

Contribute

Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

Our tools

We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

“We should forget about small efficiencies, say about 97% of the time: premature optimization is the root of all evil.” - Donald Knuth