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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Subtracting Dates 1

Status
Not open for further replies.

JJOHNS

MIS
Sep 12, 2001
171
0
0
US
I'm creating a little calculator in VB.NET. The formula I'm calculating is different when the startdate entered by the user is over 90 days ago, than when it is less than 90 days ago. So, I need a way to determine if the date they entered is more than 90 days ago.

user enters: StartDate.

If Today - StartDate > 90 Then
This happens
Else
This happens
End

Can someone help me with the math that compares the dates?

Thanks
 
Have a look at the following:

Code:
        Dim _now As DateTime = Now
        Dim _startDate As DateTime = #7/25/2006#

        Dim days As Integer = DateDiff(DateInterval.Day, _now, _startDate)
        If days > 90 Then
            ' This happens
        Else
            ' This happens
        End If

Enjoy!
 
TipGiver, I'm surprised to see that you work with Option Strict OFF.

Try your example with Option Strict ON and it wont compile.


Also rather than DateDiff, what about:

[tt]Dim days As Integer = _startDate.Subtract(_now).Days[/tt]


Hope this helps.


[vampire][bat]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top