Thursday, February 1, 2007

C# Function : Date to Julian

problem:
Function to convert Date into Julian format


solution:

private string Date2Julian(DateTime dt)
{
//julianDate YYYYnnn
// YYYY = 4 digit year
// nnn = number of days since january 1 of YYYY

// Jan 1, 2005 = 2005001
// Dec 31, 2005 = 2005365

//initialize variable
string sJulianDate=string.Empty;


sJulianDate = dt.Year.ToString()+
dt.DayOfYear.ToString().PadLeft(3,'0');

return (sJulianDate);
}

No comments: