Tuesday, July 03, 2007

Displaying fiscal year with VBScript

In an effort to drive engineers bananas, at some point a financial wienie decided that a normal calendar we've been using for thousands of years just wasnt up to par. Fiscal dates took root in the government and corporate America, surely chaos would ensue..

Truthfully, fiscal dating makes more sense to companies because the organization can then make their own rules and target the start and end dates around important production times or downtime.

There are many good ways to generate the fiscal date information, I've found that one really quick and dirty way to display just the year is by using vbscript datedd and datepart.

Our example will use the Government fiscal year which starts October 1 so will need to add one year to the current year if it is October, Nov, or Dec.

<%
if (DatePart("M",Date)) = "10" then
FISCALYEAR = DateAdd("yyyy",1,date)

elseif (DatePart("M",Date)) = "11" then
FISCALYEAR = DateAdd("yyyy",1,date)

elseif (DatePart("M",Date)) = "12" then
FISCALYEAR = DateAdd("yyyy",1,date)

else
FISCALYEAR = DateAdd("yyyy",0,date)
end if
%>

If your fiscal year starts in, say, August.. August is the 8th month so start your script with
if (DatePart("M",Date)) = "8" then
and then continue through the months through the end of the year (12). Happy scripting, or rather, fiscalling!

If you read this far,  you should follow me on Twitter!

2 comments:

  1. Where there is fiscal years, there is typically fiscal months.. Below is a solution to produce fiscal months:

    'OCTOBER
    if (DatePart("M",Date)) = "10" then
    FISCALMONTH = "01"

    'NOVEMBER
    elseif (DatePart("M",Date)) = "11" then
    FISCALMONTH = "02"

    'DECEMBER
    elseif (DatePart("M",Date)) = "12" then
    FISCALMONTH = "03"

    'JANUARY
    elseif (DatePart("M",Date)) = "1" then
    FISCALMONTH = "04"

    'FEBRUARY
    elseif (DatePart("M",Date)) = "2" then
    FISCALMONTH = "05"

    'MARCH
    elseif (DatePart("M",Date)) = "3" then
    FISCALMONTH = "06"

    'APRIL
    elseif (DatePart("M",Date)) = "4" then
    FISCALMONTH = "07"

    'MAY
    elseif (DatePart("M",Date)) = "5" then
    FISCALMONTH = "08"

    'JUNE
    elseif (DatePart("M",Date)) = "6" then
    FISCALMONTH = "09"

    'JULY
    elseif (DatePart("M",Date)) = "7" then
    FISCALMONTH = "10"

    'AUGUST
    elseif (DatePart("M",Date)) = "8" then
    FISCALMONTH = "11"

    'SEPTEMBER
    elseif (DatePart("M",Date)) = "9" then
    FISCALMONTH = "12"
    end if

    ReplyDelete