Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get date from day of year

Tags:

c#

datetime

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 22.2.2014. But this doesn't work, what should I do? Thanks in advance.

like image 339
tubefavorites.com Avatar asked Feb 22 '14 21:02

tubefavorites.com


People also ask

How do you calculate day of year from date?

Take the last 2 digits of the year. Divide it by 4 and discard any remainder. Add the day of the month to the value obtained in step 2. Add the month's key value, from the following table to the value obtained in step 3.


1 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("d.M.yyyy");   // The date in requested format
like image 172
Ashley Medway Avatar answered Oct 11 '22 13:10

Ashley Medway