Coding | .NET | C♯ | Angular | Ionic | Cordova | :-o

Menu

Nifty Extension Methods For DateTime in C#

These are some easy and quick date extensions which will make your life easier with dates. You can copy these extension methods in a CS file in your project and Intellisense will be more than happy to join these methods in the armory of its DateTime methods.

We will write all our static extension methods inside this DateExtensions class.

Start Date of The Week

You wish to get start date of the week to which the date belongs. You also want that the date returned should adhere to the culture of the device/thread because different cultures have different first day of week. In some cultures Monday is the first day of the week, in some Sunday, and in some Friday. Usage scenario where you might want to use this method is – Sub-total of some value in the duration of the week of the give date or current date. Here is the method: