|
-
Oct 6th, 2009, 04:13 AM
#1
Thread Starter
Hyperactive Member
[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.????
-
Oct 6th, 2009, 04:59 AM
#2
Re: Date Differences
The DateDiff function will return minus values. In your code you have used
Code:
If DateDiff(DateInterval.Minute, DateGen, Now) >= 1 Then
If the Now value is Greater than it will return + values. If the Now Value is Lesser tha DateGen it will return - values. You need to change your code Accordingly.
Code:
DateDiff(DateInterval.Minute, Date1, Date2)
If the Date2 is Greater it will return +
If the Date2 is Lesser it will return _ values
Please mark you thread resolved using the Thread Tools as shown
-
Oct 6th, 2009, 08:04 AM
#3
Thread Starter
Hyperactive Member
Re: Date Differences
Ah, stupid me!!!!
Thank you so much!
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|