adding date
-
hi i wish to add a value to date example 1/1/2005 add 4 days ahead so the date will be 5/1/2005 may i know how to do this by code? i try this way dim a as date a= today +4 but there is an error here state that + cannot be done by date n integer may i know how to add it to date? thank you in advance Gary
-
hi i wish to add a value to date example 1/1/2005 add 4 days ahead so the date will be 5/1/2005 may i know how to do this by code? i try this way dim a as date a= today +4 but there is an error here state that + cannot be done by date n integer may i know how to add it to date? thank you in advance Gary
You can add DateTime and TimeSpan:
DateTime nowPlusFourHours = DateTime.Now + new TimeSpan(4, 0, 0, 0)
You can also substract one DateTime from another one and get a TimeSpan back. -
You can add DateTime and TimeSpan:
DateTime nowPlusFourHours = DateTime.Now + new TimeSpan(4, 0, 0, 0)
You can also substract one DateTime from another one and get a TimeSpan back.hi robert i dont understand...... DateTime? i try typing it it say here DateTime is a type and cannot be used as an expression so i try this way
Dim a As Date a = DateTime.Now + New TimeSpan(4, 0, 0, 0)
but ending up it say operator "+" is not define for "Date" and "TimeSpan" can please explain in more detail? im using vb.net thanks Gary -
hi robert i dont understand...... DateTime? i try typing it it say here DateTime is a type and cannot be used as an expression so i try this way
Dim a As Date a = DateTime.Now + New TimeSpan(4, 0, 0, 0)
but ending up it say operator "+" is not define for "Date" and "TimeSpan" can please explain in more detail? im using vb.net thanks GaryYou are right, sorry. Sometimes I mix up C# and VB.Net :-D You should use:
Dim a As Date a = DateTime.Now.Add(New TimeSpan(4, 0, 0, 0))
-
You are right, sorry. Sometimes I mix up C# and VB.Net :-D You should use:
Dim a As Date a = DateTime.Now.Add(New TimeSpan(4, 0, 0, 0))
There is also DateTime.Now.AddDays(4) :)