Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you convert a DateTime to JulianDate?

I need to convert a DateTime to a julian date in YYDDD format. How do you do it? I have seen there is a JulianCalendar class in .net but cannot find any example how to do the conversion. I have seen few links but none of them work.

any suggestions?

UPDATE I have been given some date to convert to a csv file and this include converting a dateTime to a format that i cannot change apparently is used in the banking world. format is YYDDD .After some googling it looked like it was julian calendar. I might be wrong.So here iam an totally confused of what format that is.

like image 491
user712923 Avatar asked Nov 17 '25 13:11

user712923


1 Answers

It looks like this format is indeed also called Julian Date in the mainframe world...

http://www.google.com/search?sourceid=chrome&ie=UTF-8&q=julian+date+yyddd

var myDate = DateTime.Now;
string.Format("{0:yy}{1:D3}", myDate, myDate.DayOfYear);

EDIT - To convert such a string back to a date, one can use something like this:

DateTime FromBizarreMainframeFormat(string julianDate) {
    // TODO add validation logic, plus rules to cope with pre-2000 dates
    var yy = 2000 + int.Parse(julianDate.SubString(0,2));
    var ddd = int.Parse(julianDate.Substring(2));
    return new DateTime(yy, 1, 1).AddDays(ddd);
}
like image 133
jeroenh Avatar answered Nov 19 '25 05:11

jeroenh