does anyone know how to subtract a certain number of days from a given date?
thanks in advance for your help.
Nevermind I figured it out with the help of the help index.
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;
TimeSpan span=dt.Date.Subtract(dt.AddDays(-5));
TextBox1.Text=Convert.ToString(span.Days);
From
Himanshu Sharma
shortest:
TextBox1.Text = DateTime.Now.AddDays(-3)
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)
futureTime = futureTime .Add(myTimeSpan)
End If
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.