jueves, 3 de diciembre de 2009

Función Days360 en Vb.Net y C#

Código C#:
public static int CalculateDays360(DateTime d1, DateTime d2)
{
int years = d2.Year - d1.Year;
int months = d2.Month - d1.Month;

int dayNo1 = 0;
int dayNo2 = 0;

dayNo2 = d2.Day;
dayNo1 = d1.Day;

if (dayNo1 == 31) dayNo1 = 30;
if (dayNo2 == 31) dayNo2 = 30;

int days = dayNo2 - dayNo1;
return years * 360 + months * 30 + days;
}

Código VB.Net:

Public Shared Function CalculateDays360(ByVal d1 As DateTime, ByVal d2 As DateTime) As Integer
Dim years As Integer = d2.Year - d1.Year
Dim months As Integer = d2.Month - d1.Month

Dim dayNo1 As Integer = 0
Dim dayNo2 As Integer = 0
dayNo2 = d2.Day
dayNo1 = d1.Day
If (dayNo1 = 31) Then dayNo1 = 30
If (dayNo2 = 31) Then dayNo2 = 30
Dim days As Integer = dayNo2 - dayNo1
Return years * 360 + months * 30 + days
End Function

No hay comentarios: