Posted By

Scooter on 03/12/08


Tagged

DateTime


Versions (?)

Who likes this?

5 people have marked this snippet as a favorite

Netzach
sveggiani
emoseman
joethermal
derekbrown


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 daysInMonth($year, $month)
  14. {
  15. return date("t", strtotime($year . "-" . $month . "-01"));
  16. }
  17.  
  18. ?>

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")); }

Posted By: receter on May 26, 2011

caldaysinmonth(CALGREGORIAN, 2, 2005); (PHP 4 >= 4.1.0, PHP 5)

Posted By: receter on May 26, 2011

http://at2.php.net/manual/de/function.cal-days-in-month.php

You need to login to post a comment.