Instead of handling this yourself in C#, you could simply use the JulianCalendar class
And to get today in the Julian calendar, you could do:
JulianCalendar calendar = new JulianCalendar();
var today=DateTime.Today;
var dateInJulian = calendar.ToDateTime(today.Year, today.Month, today.Day, today.Hour, today.Minute, today.Second, today.Millisecond);
EDIT:
And I realized I didn't help you with a good way to get a result in the YYJJJ format you were looking for, it's quite simple:
var stringResult=string.Format("{0}{1}", dateInJulian.ToString("yy"), dateInJulian.DayOfYear);
Sadly, I don't think there's an equivalent of dateTime.ToString("JJJ");
that will give the day of the year, hence my little string.Format()
work-around, but it works just as well!
EDIT2:
So Phoog educated me a bit below in the comments, and pointed out that you weren't looking for today in the Julian Calendar, which is what the above code would give in respect to the JulianCalendar class. Rather, it appears you're looking for the Ordinal date (this piece added for future reader clarification). I'm going to leave the above so that someone doesn't make the same mistake that I did. What you really want, I believe, is the code from the first edit but without the JulianCalendar business, so:
var dateToConvert = DateTime.Today // Or any other date you want!
var stringResult=string.Format("{0}{1}", dateToConvert.ToString("yy"), dateToConvert.DayOfYear);
DateTime.DayOfYear
works quite well. For Excel, see cpearson.com/excel/jdates.htm – Jim Mischel