How can I get date from day of year in c #?
date
day of year
I have this code:
int a = 53; // This is the day of year value, that I got previously string b = Convert.ToDateTime(a).ToString(); // Trying to get the date
I need to get the value on 22.2.2014 . But it does not work, what should I do? Thanks in advance.
22.2.2014
int dayOfYear = 53; int year = DateTime.Now.Year; //Or any year you want DateTime theDate = new DateTime(year, 1, 1).AddDays(dayOfYear - 1); string b = theDate.ToString("dMyyyy"); // The date in requested format
Assuming you want the current year?
int a = 53; DateTime date = new DateTime(DateTime.Now.Year, 1,1).AddDays(a -1);
int a = 53; var dt = new DateTime(DateTime.Now.Year, 1, 1).AddDays(a - 1); string b = dt.ToString();
Using
DateTime.AddDays()
Initialize the date before the beginning of the year and then just add a to this function
a
http://msdn.microsoft.com/en-us/library/system.datetime.adddays(v=vs.110).aspx