26 Juni 2012

TimeSpan and Date Substract


Public Class Tester
    Public Shared Sub Main
        Dim birthDay As Date
        Dim lifeTime As TimeSpan
        Dim lifeDays As Integer


        birthDay = Date.Parse("December 25, 2007")
        lifeTime = Now.Subtract(birthDay)
        lifeDays = lifeTime.Days
        Console.WriteLine(String.Format_
           "There are {0} days between {1:D} and {2:D}", _
           lifeDays, birthDay, Now))
    End Sub
End Class
There are -227 days between December 25, 2007 and May 11, 2007

kl

Add TimeSpan to Date
Option Strict On

Public Class DateMembers
   Public Shared Sub Main()
      Dim dat As Date = New Date(200011)
      Dim ts As New TimeSpan(30000)
      Console.WriteLine("The original date is " & dat)

      dat = dat.AddMonths(5)
      Console.WriteLine("The new date is " & dat)

      dat = dat + ts
      Console.WriteLine("The new date is " & dat)
   End Sub
End Class
The original date is 01/01/2000
The new date is 01/06/2000
The new date is 01/07/2000

Tidak ada komentar:

Posting Komentar