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.
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);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With