Hi
I am trying to convert a function from a VB (version 6.5) macro in Excel 2007 to c#. But there is a date calculation which I don't understand. Can someone please tell me what the following does?
etcFunction CalcRate(D As Date) As Double Dim B, Dmin1 as Date, Dplus1 as Date Dmin1 = DateSerial(Year(D), 1, 1) Dplus1 = DateSerial(Year(D) + 1, 1, 1) B = (Dplus1 - D) / (Dplus1 - Dmin1)
Thanks,
Peter
Hi,
The user types =CalcRate(date) in Excel, where date is a valid date number.
The function evaluates two date variables. Dmin1 evaluates to the 1st January for the year containing the date passed, and the Dplus1 evaluates to the 1st January for the following year. So if the date passed is say 13 March 2009, Dmin1 = 1 Jan 2009 and DPlus1 = 1 Jan 2010.
The B variable takes the number of days between the date passed and the next 1st Jan and divides this by the number of days between 1st Jan in the date year and the 1st Jan in the following year.
i.e. it's working out the % of the calendar year that's left as a decimal.
HTH
Last edited by Richard Buttrey; 11-18-2010 at 07:57 PM.
Richard Buttrey
If this was useful then please rate it appropriately.
Click the small star iconat the bottom left of my post.
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks