Get the first day of the current week

Here is a quick way to get the first day of the current week.

If you are happy with sunday as the first day of the week, then you can simply do this :


 public static DateTime FirstDayOfWeek(this DateTime date)
 {
            return DateTime.Today.AddDays(-(int)DateTime.Today.DayOfWeek);
 }

But if you want that the first day of the week matches your culture (eg: the belgian week starts on monday), you have to take care of the culture’s DateTime format.

So the method will change a bit :


public static DateTime FirstDayOfWeek(this DateTime date)
{
     return DateTime.Today.AddDays(-((int)DateTime.Today.DayOfWeek - (int)CultureInfo.CurrentCulture.DateTimeFormat.FirstDayOfWeek));
}

Usage :

    DateTime FirstDayOfWeek = DateTime.Today.FirstDayOfWeek();

or

 DateTime FirstDayOfWeek = DateTime.Now.FirstDayOfWeek();

Incoming search terms:

  • asp net get first day of week
  • first day of week in asp net
  • get first day of the week in linq
  • jquery get first day of current week
  • linq how to get the first day of a week
  • net first day of week

JS Mixer is released

CSS mixer is really cool.  Good job.  Is there a JavaScript mixer?

It’s the main content of a mail I received last week.

It decided me to write a JS Mixer application, based on CSS Mixer.
The big part of the work was already done, I just needed to adapt my code.

Just like CSS Mixer, you can download it from codeplex : http://jsmixer.codeplex.com/

You can also download it from some software websites.

JSMixer antivirus scan report at softoxi.com

Remark :

With ASP.NET WebForms, you can achieve the same result by setting a few propertie to the ScriptManager control.

But the advantage to use a tool like JSMixer, is that your server doesn’t have to do the work : it’s already done !

And when you spare some work to your server, your server is happy !