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.
VB.Net: Add to date
From Wiki
Adding a day, a month or a year to a date in VB.Net is very easy but takes some getting used to.
Here is the code.
- Module Module1
- Sub Main()
- Dim _Date As New Date(2008, 6, 12)
- Console.WriteLine("begin")
- Console.WriteLine(_Date.ToString("dd/MM/yyy"))
- _Date = _Date.AddDays(10)
- Console.WriteLine("added 10 days")
- Console.WriteLine(_Date.ToString("dd/MM/yyy"))
- _Date = _Date.AddMonths(10)
- Console.WriteLine("added 10 months")
- Console.WriteLine(_Date.ToString("dd/MM/yyy"))
- _Date = _Date.AddYears(10)
- Console.WriteLine("added 10 years")
- Console.WriteLine(_Date.ToString("dd/MM/yyy"))
- _Date = _Date.Add(New TimeSpan(10, 0, 0, 0, 0))
- Console.WriteLine("added 10 days with timespan")
- Console.WriteLine(_Date.ToString("dd/MM/yyy"))
- Console.ReadLine()
- End Sub
- End Module
The americans just have to switch the dd and MM to make it more readable to them.
Just a little warning _date.adddays onitself will not add anything to _date which is a bit strange if you first try this.
If you run the above you will see the following.




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