[RESOLVED] Date Differences
OK, firstly, I know about DateDiff and TimeSpan...
I am doing a project. I save a date in the registry. Now, I have to test this date against today's date and calculate the differences in minutes, hours, days, months, weeks and years.
I save the date in the registry like this:
Code:
Application.UserAppDataRegistry.SetValue("Date", [Date])
I then made a sub to calculate the differences:
Code:
Private Sub Calculate()
Try
Dim DateGen As Date
DateGen = CType([Date], Date)
Select Case TimePeriod
Case "Every Minute"
If DateDiff(DateInterval.Minute, DateGen, Now) >= 1 Then
RandomAlpha()
End If
Case "Every x Minute(s)" '
If DateDiff(DateInterval.Minute, Now, DateGen) >= Duration Then
RandomAlpha()
End If
Case "Every Hour"
If DateDiff(DateInterval.Hour, DateGen, Now) >= 1 Then
RandomAlpha()
End If
Case "Every x Hour(s)"
If DateDiff(DateInterval.Hour, DateGen, Now) >= Duration Then
RandomAlpha()
End If
Case "Every Day"
If DateDiff(DateInterval.Day, DateGen, Now) >= 1 Then
RandomAlpha()
End If
Case "Every x Day(s)"
If DateDiff(DateInterval.Day, DateGen, Now) >= Duration Then
RandomAlpha()
End If
Case "Every Week"
If DateDiff(DateInterval.Day, DateGen, Now) >= 7 Then
RandomAlpha()
End If
Case "Every x Week(s)"
If DateDiff(DateInterval.Day, DateGen, Now) >= (Duration * 7) Then
RandomAlpha()
End If
Case "Every Month"
If DateDiff(DateInterval.Month, DateGen, Now) >= 1 Then
RandomAlpha()
End If
Case "Every x Month(s)"
If DateDiff(DateInterval.Month, DateGen, Now) >= Duration Then
RandomAlpha()
End If
Case "Every Year"
If DateDiff(DateInterval.Year, DateGen, Now) >= 1 Then
RandomAlpha()
End If
Case "Every x Year(s)"
If DateDiff(DateInterval.Year, DateGen, Now) >= Duration Then
RandomAlpha()
End If
End Select
Catch eg As Exception
MessageBox.Show(eg.Message())
tmrCalcGen.Enabled = False
End Try
End Sub
As you can see, based on the difference between these dates ( today's date and the registry date ), a sub gets called and the program continues.
Unfortunately, the minutes and hours never calls the RandomAlpha sub, because, I think it gets the wrong answer.
How can I calculate the difference in minutes, hours etc.????