Compare Date in Vb.net using Datareader
My req开发者_如何学Pythonuiremnet is i want to compare two data values in my database.These two dates belong to two different columns. What i want to compare is if the date of one column greater by 6 months from the date of other column then it should give error. I want to pass this query to database and check,and later on depending on the result want to insert my other functionality
If you have two date objects ReturnDate
and IssueDate
and you want to compare them to check if ReturnDate - IssueDate >= 6 Months:
'For this example the two dates are static and not from database':
Dim ReturnDate = Date.Now
If ReturnDate = Nothing Then ReturnDate = Date.Now 'Not initialized, equal to ReturnDate = Date.MinValue
Dim IssueDate = ReturnDate.AddMonths(-6).AddDays(-1) 'more than 6 Months before
Dim halfYearBefore = ReturnDate.AddMonths(-6)
If IssueDate <= halfYearBefore Then
'this code will actually go here, show error etc.
End If
If you have problems to retrieve the date-values from dababase with ADO.NET, have a look at following link: http://msdn.microsoft.com/en-us/library/bh8kx08z.aspx
精彩评论