Quantcast
Channel: VBForums - Visual Basic .NET
Viewing all articles
Browse latest Browse all 27514

VS 2008 [RESOLVED] Date Difference

$
0
0
hi
i have to find the date difference between 2 dates. i have to give discount to the person if the second date is within 12 months.
i have used :
HTML Code:

Dim mMonths As Integer = DateDiff(DateInterval.Month, dtPkTransferDate.Value.Date, dtPkDelDate.Value.Date)
and also the following code :
HTML Code:

Public Function CompleteMonthsBetween(ByVal mFDate As DateTime, ByVal mEDate As DateTime) As Integer

        Dim invertor = 1

        If (mFDate > mEDate) Then
            Dim tmp = mEDate
            mEDate = mFDate
            mFDate = tmp
            invertor = -1
        End If

        Dim diff = ((mEDate.Year - mFDate.Year) * 12) + mEDate.Month - mFDate.Month

        If mFDate.Day > mEDate.Day Then
            Return (diff - 1) * invertor
        Else
            Return diff * invertor
        End If
    End Function

but my prob. is say the goods where sold on 01/04/2012 (dd/mm/yyyy) format and the renewal is being done on 02/04/2013
i am getting the months difference as 12 where as it should be 13

or what else should i do to get the actual months. it might be very simple but i am puzzled.
pls. guide.
thankx in advance

Viewing all articles
Browse latest Browse all 27514

Trending Articles