• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 161
  • Last Modified:

time

I am getting an error. I want to check to see if it more than 30 day.

                Dim TmpClosedDated As Date = "02/1/08"
                    Dim myDifTime As TimeSpan

                    Dim DifTime As String

                    myDifTime = DateTime.Now.ToString("MM/dd/yy") - TmpClosedDated   < ---- here

                    If myDifTime.TotalDays > 30 Then
                  
                 ' do whatever

                    End If
0
VBdotnet2005
Asked:
VBdotnet2005
  • 2
2 Solutions
 
Jorge PaulinoIT Pro/DeveloperCommented:
Why don't you use:

Dim diff As Long = DateDiff(DateInterval.Day, TmpClosedDated , DateTime.Now.Date)
0
 
VBdotnet2005Author Commented:
What is DateDiff?
0
 
Jorge PaulinoIT Pro/DeveloperCommented:
Well returns the number of intervals between two dates. Since you whant to check if the difference is bigger then 30 you can use that. You can read more in http://msdn2.microsoft.com/en-us/library/xhtyw595.aspx

Dim diff As Long = DateDiff(DateInterval.Day, TmpClosedDated , DateTime.Now.Date)
If diff > 30 Then
 ' Your code
End If
0
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
Just do:

        Dim TmpClosedDated As Date = "02/1/08"
        If DateTime.Now.Subtract(TmpClosedDated).TotalDays > 30 Then

        End If
0

Featured Post

The 14th Annual Expert Award Winners

The results are in! Meet the top members of our 2017 Expert Awards. Congratulations to all who qualified!

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now