Hey I am looking to create a Julian date format like YYDDD from the current date where the DDD would be the number of days since the year began.
Is there any .NET functions to do this easily ?
Hey I am looking to create a Julian date format like YYDDD from the current date where the DDD would be the number of days since the year began.
Is there any .NET functions to do this easily ?
Since, if you're working with Julian dates, you probably will need to do this again and again, I suggest writing an extension function for System.DateTime, which would execute something like the following:
return (DateTime.Year % 100) * 1000 + DateTime.DayOfYear
ETA: If what you want to do is convert a DateTime to the Julian date format (create a formatted string in Julian date format), I still suggest an extension function, but it would look like this:
public static string ToJulianDate(this DateTime date)
{
return string.Format("{0:00000}", (date.Year % 100) * 1000 + date.DayOfYear);
}
No functions that I can think of, but maybe this would help:
Public Function Date2Julian(ByVal vDate As Date) As Long
Date2Julian = CLng(Format(Year(vDate), "0000") _
+ Format(DateDiff("d", CDate("01/01/" _
+ Format(Year(vDate), "0000")), vDate) _
+ 1, "000"))
End Function
Here are a couple that may help:
public double GetJulianDate(DateTime pdtmDate)
{
DateTime dtmStart = new DateTime(1,1,1);
TimeSpan objTS = new TimeSpan(pdtmDate.Ticks - dtmStart.Ticks);
return objTS.TotalDays + 1721637;
}
Public Function Date2Julian(ByVal vDate As Date) As Long
Date2Julian = CLng(Format(Year(vDate), "0000") _
+ Format(DateDiff("d", CDate("01/01/" _
+ Format(Year(vDate), "0000")), vDate) _
+ 1, "000"))
End Function