Tuesday, 5 November 2013

Get financial year using C#

Get financial year using C# :

Like 13-14 instead of (2013-2014)

// The following C# function used to get the Financial year from the given date


       public static string GetFinancialYear(string cdate)
        {
            string finyear = "";
            DateTime dt = Convert.ToDateTime(cdate);
            int m = dt.Month;
            int y = dt.Year;
            if (m > 3)
            {
                finyear = y.ToString().Substring(2, 2) + "-" + Convert.ToString((y + 1)).Substring(2,2);   
                //get last  two digits (eg: 10 from 2010);
            }
            else
            {
                finyear = Convert.ToString((y - 1)).Substring(2, 2) + "-" + y.ToString().Substring(2, 2);
            }
            return finyear;
       }


 Like 13-14 instead of (2013-2014)


 public static string GetFinYear(string sdate)
        {
            string finyear = "";
            DateTime s = Convert.ToDateTime(sdate);

            int m = s.Month;
            int y = s.Year;
            if (m > 3)
            {
                finyear = y.ToString() + "-" + Convert.ToString((y + 1));
            }
            else
            {
                finyear = Convert.ToString((y - 1)) + "-" + y.ToString();
            }
            return finyear;

        }

No comments:

Post a Comment

SQL SERVER – Disk Space Monitoring – Detecting Low Disk Space on Server

CREATE PROCEDURE [CSMSDVLP].[DiskSpaceMonitor] @mailProfile nvarchar(500), @mailto nvarchar(4000), @threshold INT, @logfile nvarchar(40...