We Recommend

Wicked Cool PHP: Real-World Scripts That Solve Difficult Problems Wicked Cool PHP: Real-World Scripts That Solve Difficult Problems
Wicked Cool PHP contains a wide variety of scripts to process credit cards, check the validity of email addresses, template HTML, and serve dynamic images and text.


Posted By

Scooter on 03/12/08


Tagged

DateTime


Versions (?)


Who likes this?

1 person has marked this snippet as a favorite

Netzach


Number of days in a month


Published in: PHP 


URL: http://reusablecode.blogspot.com

Returns the number of days in a given month for a given year.


  1. <?php
  2. /*
  3.   Copyright (c) 2008, reusablecode.blogspot.com; some rights reserved.
  4.   Thanks to Jim Mayes for showing me a more elegant solution.
  5.  
  6.   This work is licensed under the Creative Commons Attribution License. To view
  7.   a copy of this license, visit http://creativecommons.org/licenses/by/3.0/ or
  8.   send a letter to Creative Commons, 559 Nathan Abbott Way, Stanford, California
  9.   94305, USA.
  10.   */
  11.  
  12. // Returns the number of days in a given month (and in the case of February, for the given year).
  13. function MonthDays($someMonth, $someYear)
  14. {
  15. return date("t", strtotime($someYear . "-" . $someMonth . "-01"));
  16. }
  17. ?>

Report this snippet 

Comments

RSS Icon Subscribe to comments
Posted By: jimmayes on March 26, 2008

function daysinmonth($year, $month){ return date("t", strtotime($year . "-" . $month . "-01")); }

Posted By: jimmayes on March 26, 2008

function daysinmonth($year, $month){ return date("t", strtotime($year . "-" . $month . "-01")); }

You need to login to post a comment.