cal_days_in_month() not present

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • exoskeleton
    New Member
    • Sep 2006
    • 104

    #1

    cal_days_in_month() not present

    hi dear experts... does cal_days_in_mon th() function is not present in php 4.4.4? i test the function with the code function_exist and return NOT PRESENT.

    what is the other walk-around or alternative way to function as cal_days_in_mon th()?

    please help...Thank you
  • exoskeleton
    New Member
    • Sep 2006
    • 104

    #2
    anyone please help...

    Comment

    • adamalton
      New Member
      • Feb 2007
      • 93

      #3
      The bodge version is to use a switch statement:

      switch($month)
      {
      case 01: $days=31; break;
      case 03: $days=31; break;
      case 04: $days=30: break;
      etc etc.....
      }

      Obviously in the case of February you need to work out if it's a leap year or not. I'd use date('L', $timestamp);

      Comment

      • exoskeleton
        New Member
        • Sep 2006
        • 104

        #4
        Originally posted by adamalton
        The bodge version is to use a switch statement:

        switch($month)
        {
        case 01: $days=31; break;
        case 03: $days=31; break;
        case 04: $days=30: break;
        etc etc.....
        }

        Obviously in the case of February you need to work out if it's a leap year or not. I'd use date('L', $timestamp);
        I'll try your code sir...thank you

        Comment

        • rogerpride
          New Member
          • Mar 2007
          • 7

          #5
          if your user inputs the month and year, use this:

          $lastday = date("d", mktime(0, 0, 0, $month +1, 0, $year));
          echo $lastday;

          adding 1 to the month and setting the day at 0 forces date() to subtract a day, giving you the last day of the given month.

          if you want the number of days in the current month modify it like this:

          $month = date("n");
          $year = date("Y");
          $lastday = date("d", mktime(0, 0, 0, $month +1, 0, $year));
          echo $lastday;

          That's the easiest way I know of.

          Comment

          Working...