In this post we will see, generating a Financial Year string based on the given date.
I have given code in C#.Net and VB.Net.
C#.Net Method to Get Financial Year of a given Date :

    /// <summary>
    /// Method to Get Financial Year of a given Date
    /// </summary>
    /// <param name=”curDate”></param>
    /// <returns></returns>
    public string GetFinancialYear(DateTime curDate)
    {
        int CurrentYear = curDate.Year;
        int PreviousYear = (curDate.Year – 1);
        int NextYear = (curDate.Year + 1);
        string PreYear = PreviousYear.ToString();
        string NexYear = NextYear.ToString();
        string CurYear = CurrentYear.ToString();
        string FinYear = null;
        if (curDate.Month > 3)
        {
            FinYear = CurYear + “-“ + NexYear;
        }
        else
        {
            FinYear = PreYear + “-“ + CurYear;
        }
        return FinYear;
    }

VB.Net Method to Get Financial Year of a given Date :

    ”’ <summary>
    ”’ Method to Get Financial Year of a given Date
    ”’ </summary>
    ”’ <param name=”curDate”></param>
    ”’ <returns></returns>
    ”’ <remarks></remarks>
    Public Function GetFinancialYear(ByVal curDate As DateTime) As String
        Dim CurrentYear As Integer = curDate.Year
        Dim PreviousYear As Integer = curDate.Year – 1
        Dim NextYear As Integer = curDate.Year + 1
        Dim PreYear As String = PreviousYear.ToString()
        Dim NexYear As String = NextYear.ToString()
        Dim CurYear As String = CurrentYear.ToString()
        Dim FinYear As String = Nothing
        If (curDate.Month > 3) Then
            FinYear = CurYear + “-“ + NexYear
        Else
            FinYear = PreYear + “-“ + CurYear
        End If
        Return FinYear
    End Function

Leave a Reply

Your email address will not be published. Required fields are marked *