C # - How to calculate the current day of the year?

Today is 5.27.2010 - this means that it is day 147 of this year.

How can I calculate that today is 147 based on the current date?

+4
source share
5 answers

There is a DateTime property called: DayOfYear

 Console.WriteLine(DateTime.Now.DayOfYear); 

Or for any date:

 var d = new DateTime(2010, 5, 30); Console.WriteLine(d.DayOfYear); 
+18
source

Actually, this is pretty easy:

 int dayOfYear = DateTime.Today.DayOfYear; 
+4
source

The C # DateTime class has a DayOfYear() method that you could use.

+3
source

Has anyone mentioned the DateTime.DayOfYear property?

+3
source
 DateTime dt = new DateTime(2001, 12, 14); dynamic dayofyear = dt.DayOfYear; dynamic datofweek = dt.DayOfWeek; 
-1
source

Source: https://habr.com/ru/post/1311112/


All Articles