Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Simple Date Question Adding one Day

Status
Not open for further replies.

ghost2

Programmer
Aug 7, 2003
145
0
0
US
I am trying to add + 1 to a date and in VB.Net it does not like it. How can I add 1 day to a date variable? Thanks all
 
Use the add hours function to add 24 hours to the date

dim d as date=#01/01/2004#

private sub addDay
' Increment date by one day
d=d.addhours(24)
end sub
 
You can also do it like this:
Code:
Dim MyDate As New DateTime(1963, 11, 22)
Dim MyTimeSpan as New TimeSpan(1, 0, 0, 0)
Dim MyNewDate as New DateTime

MyNewDate = MyDate.Add(MyTimeSpan)
If you were in C#, you could use the addition operator (+) to add the timespan to your datetime value:
Code:
MyNewDate = MyDate + MyTimeSpan;
Chip H.


If you want to get the best response to a question, please check out FAQ222-2244 first
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top