[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Day of the yesr



PureBytes Links

Trading Reference Links

> I know someone recently used a calculation for this and I thought at
> the time that I would never need it but .. I do .. Can someone give
> the method of calculating the numerical day of the year so that the
> first day of trading in January =1 and the next= 2 etc.? 

How about 

DateToJulian(Date) - DateToJulian(10000*Year(Date) + 101) + 1

Except that will number the *calendar* dates of the year, not the 
trading dates.  If you really need the ordinal number of the 
trading date, the only guaranteed-correct way to do it is to 
count it as you go.  Otherwise holidays, market closings, etc 
could mess up your calculation.  So you could do this:

if Year(Date) <> Year(Date[1]) then TradingDay = 0;
if Date <> Date[1] then TradingDay = TradingDay + 1;

Gary