|
-
Jul 5th, 2006, 02:12 AM
#1
Thread Starter
Lively Member
[RESOLVED] Comparing DateTimes, need help
I would like to compare 2 datetimes; datetime are in format MM/dd/yyyy HH:mm:ss.
DateTimes should be compared to minutes, excluding seconds.
E.g. 07/05/2006 09:30:30 and 07/05/2006 09:30:45, in this case dates are the same and times too (because I have excluded seconds in the comparing),
instead:
07/05/2006 09:30:30 and 07/05/2006 09:31:30 are different.
How can I do?
Thank
-
Jul 5th, 2006, 02:24 AM
#2
Re: Comparing DateTimes, need help
DateTimes are NOT in ANY format at all. DateTimes are DateTimes and DateTimes have no format. It is only when you convert the DateTime to a string that format comes into play, because the string can display the date and time in a number different ways.
Now we've established that, you just need to remove the seconds from your two Dates and compare:
VB Code:
'Remove the seconds component.
Dim dt1 As Date = DateTime1.AddSeconds(-DateTime1.Second)
Dim dt2 As Date = DateTime2.AddSeconds(-DateTime2.Second)
Select Case Date.Compare(dt1, dt2)
Case Is < 0
MessageBox.Show("DateTime1 is before DateTime2")
Case 0
MessageBox.Show("DateTime1 is the same as DateTime2")
Case Is > 0
MessageBox.Show("DateTime1 is after DateTime2")
End Select
-
Jul 5th, 2006, 04:38 AM
#3
Thread Starter
Lively Member
Re: [RESOLVED] Comparing DateTimes, need help
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
|