Login or Sign Up to become a member!
LessThanDot Sit Logo

LessThanDot

Community Wiki

Less Than Dot is a community of passionate IT professionals and enthusiasts dedicated to sharing technical knowledge, experience, and assistance. Inside you will find reference materials, interesting technical discussions, and expert tips and commentary. Once you register for an account you will have immediate access to the forums and all past articles and commentaries.

LTD Social Sitings

Lessthandot twitter Lessthandot Linkedin Lessthandot friendfeed Lessthandot facebook Lessthandot rss

Note: Watch for social icons on posts by your favorite authors to follow their postings on these and other social sites.

Navigation

Google Ads

VB.Net: Substract from a date (days, months, years)

From Wiki

Jump to: navigation, search

To substract you have to add

  1. Module Module1
  2.  
  3.     Sub Main()
  4.         Dim _Date As New Date(2008, 6, 12)
  5.         Console.WriteLine("begin")
  6.         Console.WriteLine(_Date.ToString("dd/MM/yyyy"))
  7.         _Date = _Date.AddDays(-10)
  8.         Console.WriteLine("subtracting 10 days")
  9.         Console.WriteLine(_Date.ToString("dd/MM/yyyy"))
  10.         _Date = _Date.AddMonths(-10)
  11.         Console.WriteLine("subtracting 10 months")
  12.         Console.WriteLine(_Date.ToString("dd/MM/yyyy"))
  13.         _Date = _Date.AddYears(-10)
  14.         Console.WriteLine("subtracting 10 years")
  15.         Console.WriteLine(_Date.ToString("dd/MM/yyyy"))
  16.         _Date = _Date.Add(New TimeSpan(10, 0, 0, 0, 0).Negate)
  17.         Console.WriteLine("subtracting 10 days with timespan")
  18.         Console.WriteLine(_Date.ToString("dd/MM/yyyy"))
  19.         Console.ReadLine()
  20.     End Sub
  21.  
  22. End Module

Look how all the numbers are negative and how you can set a timespan to be negative by calling the negate method.

Here is the result.

Image:Resultdatesubstracting.jpg

544 Rating: 1.8/5 (5 votes cast)