does anyone know how to subtract a certain number of days from a given date?

Nevermind I figured it out with the help of the help index.

5
Contributors
4
Replies
7
Views
12 Years
Discussion Span
Last Post by marc-0

I know nothing about vb.net (sure sounds like i can help :rolleyes: )
but maybe this will work

``````Public Function TimeDiff(LesserTime As String, LesserTimeDate As String, GreaterTime As String, GreaterTimeDate As String) As String

Dim Thrs As Single, Tmins As Single, Tsecs As Single, ReturnTime As String
Dim DTcheck As Single
DTcheck = DateDiff("d", LesserTimeDate, GreaterTimeDate)

If DTcheck > 0 Then
For i = 0 To DTcheck
Hour(GreaterTime) = Hour(GreaterTime) + 24
Next
ElseIf DTcheck < 0 Then
TimeDiff = "ERROR"
Exit Function
End If

Thrs = Hour(GreaterTime) - Hour(LesserTime)
If Thrs > 0 Then
Tmins = Minute(GreaterTime) - Minute(LesserTime)
If Tmins < 0 Then
Tmins = Tmins + 60
Thrs = Thrs - 1
End If
ElseIf Thrs = 0 And Minute(GreaterTime) > Minute(LesserTime) Then
Tmins = Minute(GreaterTime) - Minute(LesserTime)
Else
TimeDiff = "ERROR"
Exit Function
End If

Tsecs = Second(GreaterTime) - Second(LesserTime)
If Tsecs < 0 Then
Tsecs = Tsecs + 60
If Tmins > 0 Then Tmins = Tmins - 1 Else Tmins = 59
End If

TimeDiff = TimeSerial(Thrs, Tmins, Tsecs)

End Function``````

It's not a big issue to subtract date from given days.You can use the "Subtract" function in ASP.NET.

E.g :-
DateTime dt=DateTime.Now;
TextBox1.Text=Convert.ToString(span.Days);

From
Himanshu Sharma

shortest:

Here is a routine to add 24 hours to the current date/time. Maybe it will help.

Dim futureTime As TimeSpan = ExecTime - Now

'if the calculated time has already passed,
'add 24 hours so it does it tomorrow

If waitTime.Hours < 0 Then
Dim myTimeSpan As New TimeSpan(24, 0, 0)