Date() kalender

Discussion in 'JavaScript' started by Zynex, Feb 21, 2007.

  1. #1
    I am making a kalendar (date picker) and I was wondering how I can retrieve the number of days in the month. I can't go and declare the number of days for every month, thats too much code and not very effecient.

    thanx in advance,

    Zynex
     
    Zynex, Feb 21, 2007 IP
  2. EvilivE

    EvilivE Peon

    Messages:
    23
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #2
    This was not originally mine but I have been using it for years but can't remember the original author. Anyways here it is:

    
    function getDaysInMonth(year, month) {
         // month: 0 = Jan, 11 = Dec
         return 32 - new Date(year, month, 32).getDate();
    }
    
    Code (markup):
     
    EvilivE, Feb 21, 2007 IP