21 Oct

first and last saturday of a month

I’m working on an expenses application. In order to do it, I need to display the entire month, with full weeks in each (from Saturday to Friday).

To do this, I need to know what date the Saturday in the first week falls, and the date of the first Saturday in the following month.

Here’s the code (assuming year is a 4-digit year, and month is a 1-12 number):

      // { start date
      var start=new Date(year, month-1, 1);
      var day=start.getDay();

      start=new Date(start-3600000*24*day);

      // }
      // { end date
      if (month==13) {
      var end=new Date(year, month-1, 1);
      var day=end.getDay();

      end=new Date((+end)+3600000*24*day);

      // }

can’t be bothered explaining it – just trust that it’s right đŸ˜‰

2 thoughts on “first and last saturday of a month

  1. wow.. good script .. it might help me with my blog.. anyways.. very thanks to you that you had written the book CMS with PHP and Jquery .. It’s really good but.. it only work on virtual hosts.. why is that so??

  2. hi Sharad – thanks!

    I’m not sure what you mean about the virtual hosts thing – I have never had a problem installing in either virtual hosts mode or in a standalone web server.

    but then, most people use virtual hosts anyway.

    do you mean virtual server?

    if so; again, there should be no problem. I have my CMS running on the laptop I’m typing on, and that’s in Linux running on the bare metal of the machine (no virtual machines).

    if you give me more detail, I can help debug. Or go to http://kvweb.me/ and post details in there.

    also, here are instructions on installing a copy of the WebME CMS (which the book is based on) in a recent Fedora installation: http://verens.com/2011/10/05/installing-webme-in-fedora-16/

Leave a Reply

%d bloggers like this: