Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Shaun E on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Date Comparison. There has to be a easier way..

Status
Not open for further replies.

jgaylord

IS-IT--Management
Apr 17, 2006
11
US
Basically its like this I need to compare Date1 to Date2 and If the 2 dates are withing 3 days forward or 3 days back of each other then perform whatever module from there... with my skill level (LOW)... I can only break each date down into month... day... year... then go through a huge module of comparision.... taking into account that February only has 28 days.... I know there has to be built in function that I dont understand how to use... that would do all of this for me. Could someone point me in the right direction please.

I hope that made sense.... please respond if dont understand.
 
You can use a TimeSpan e.g.
Code:
        Dim d1 As Date
        Dim d2 As Date
        Dim t As TimeSpan
        t = d1.Subtract(d2)
Then, just check whatever properties of the "t" object you need (in your case Days or TotalDays).


____________________________________________________________
Mark,
[URL unfurl="true"]http://aspnetlibrary.com[/url]

Need help finding an answer? Try the Search Facility or read FAQ222-2244.
 
Hi,

give this a try:

Code:
                If DateDiff(DateInterval.Day, yourdate1, yourdate2) <= 3 Then
                    'do stuff
                End If

Hope it helps !

---
[tt][COLOR=white Black]MASTA[/color][COLOR=Black lightgrey]KILLA[/color][/tt] [pipe]
 
Thanks So Much! Wow all that stuff I was doing before was so CAVEMAN, this was so easy a CAVEMAN could do it.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top