65.9K
CodeProject is changing. Read more.
Home

Determine Fiscal Date

starIconstarIconstarIconstarIcon
emptyStarIcon
starIcon

4.82/5 (5 votes)

Oct 27, 2014

CPOL
viewsIcon

15358

Extension method to determine fiscal date

Introduction

At work, I'm writing code that imports fiscal data from a series of spreadsheets. In this case, I'm retrieving fiscal month/year as opposed to the calendar month/year. This means I had to convert the specified date. For instance, the US government uses October as the beginning of the fiscal year, so some minor math was involved. This extension method should work for any month you might happen to use.

The Code

This extension method will convert the specified date to the appropriate fiscal date:

public static class ExtendDateTime
{
    public static DateTime FiscalDate(this DateTime thisDate, int fiscalStartMonth)
    {
        return thisDate.AddMonths(13 - fiscalStartMonth);
    }
}

Using the code

Usage is pretty simple. In the example below, I'm using October for the beginning of the fiscal year:

DateTime fiscalDate = DateTime.Now.FiscalDate(10).Date;

History

27 Oct 2014 - Original posting.