Gunnar Peipman's ASP.NET blog

ASP.NET, C#, SharePoint, SQL Server and general software development topics.






Some extension methods for DateTime

During one of my current projects I wrote some useful extension methods for DateTime class. I had to write custom calendar component and therefore I needed manipulate dates a little bit. Here is some extensions I would like to share with you. And, of course, comments and suggestions are welcome as always.


NB! This blog is moved to

Click here to go to article


Peter said:

"(-1)*currentDate.Day" no need for all that, just use "-currentDate.Day"

# July 16, 2008 4:18 PM

DigiMortal said:

Thanks for suggestion! :)

# July 16, 2008 4:21 PM

Patrik Hägne said:

... (-1)*currentDate.Day + 1 ...

That must be the hardest way to say "1 - currentDate.Day" ever.

# July 16, 2008 5:27 PM

DigiMortal said:

Patrik, I am sure that in my blondest moments I am able to find harder way than the one you pointed out :)

# July 17, 2008 1:43 AM

Patrik Hägne said:

Haha, I respect you for that!

# July 17, 2008 6:34 PM

DigiMortal said:

Thanks, man! :D

# July 18, 2008 1:29 AM

John said:

Thanks for the share.

just a remark, the first method seems very complicated to me , i use to do that instead:

return new DateTime(DateTime.Now.Year, DateTime.Now.Month, 1);

# July 30, 2008 10:52 AM