;

How to Get a Financial Year Using a Given Date in C#


Tutorialsrack 24/11/2019 C# Programs

In this article, we will learn how to get a financial year using a given date in C#.

Here is the code to get a financial year using a given date in c#.

Code - How to get a financial year using a given date in C#
using System;

namespace Tutorialsrack
{
    class Program
    {
        /* How to Get a Financial Year Using a Given Date in C# */
        static void Main(string[] args)
        {
            DateTime date = DateTime.Now;
            Console.WriteLine("Financial Year of Given Date ({0}) is: {1}",date,GetFinancialYear(date));
            Console.ReadKey();
        }
        public static 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 = string.Empty;
            if (curDate.Month > 3)
            {
                FinYear = CurYear + "-" +NexYear;
            }
            else
            {
                FinYear = PreYear + "-" +CurYear;
            }
            return FinYear;
        }
    }
}

 

Output

Financial Year of Given Date (24-11-2019 17:10:18) is: 2019-2020

I hope this article will help you to understand how to get a financial year using a given date in C#.

Share your valuable feedback, please post your comment at the bottom of this article. Thank you!


Related Posts



Comments

Recent Posts
Tags