How to get the date from the day of the year

How can I get date from day of year in c #?

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.

+9
source share
4 answers
 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 
+15
source

Assuming you want the current year?

 int a = 53; DateTime date = new DateTime(DateTime.Now.Year, 1,1).AddDays(a -1); 
+4
source
 int a = 53; var dt = new DateTime(DateTime.Now.Year, 1, 1).AddDays(a - 1); string b = dt.ToString(); 
+1
source

Using

 DateTime.AddDays() 

Initialize the date before the beginning of the year and then just add a to this function

http://msdn.microsoft.com/en-us/library/system.datetime.adddays(v=vs.110).aspx

+1
source

All Articles