Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

c#

datetime

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

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

like image 418
John M Avatar asked May 27 '10 17:05

John M


1 Answers

There's a DateTime property named just that: DayOfYear

Console.WriteLine(DateTime.Now.DayOfYear);

Or for any date:

var d = new DateTime(2010, 5, 30);
Console.WriteLine(d.DayOfYear);
like image 145
Ahmad Mageed Avatar answered Sep 29 '22 11:09

Ahmad Mageed