Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Determining the days in a month 1

Status
Not open for further replies.

webslinga

Programmer
Jun 20, 2006
55
US
Hey all,
I need to determine the number of days in a month if given the month and the year. What is the quickest way of doing that?
 
i've done something like this in the past, although there may be easier ways:

Code:
function getDaysInCurrentMonth() {
    $dateArray = getdate();
    $nextMonthTimeStamp = mktime ( 0, 0, 0, $dateArray['month'] + 1, -1, $dateArray['year'] );
    return date("j", $nextMonthTimeStamp );
}

echo getDaysInCurrentMonth();
?>



*cLFlaVA
----------------------------
[tt]"quote goes here"[/tt]
[URL unfurl="true"]http://www.coryarthus.com/[/url]
 
eh, that's kinda sloppy.

given the month and year (as you said), i'd do this:

Code:
function getDaysInCurrentMonth($intMonth, $intYear) {
    $intYear = ($intMonth == 11) ? ($intYear + 1) : $intYear;
    $nextMonthTimeStamp = mktime ( 0, 0, 0, $intMonth + 1, -1, $intYear );
    return date("j", $nextMonthTimeStamp );
}

echo getDaysInCurrentMonth(6, 2006);
?>



*cLFlaVA
----------------------------
[tt]"quote goes here"[/tt]
[URL unfurl="true"]http://www.coryarthus.com/[/url]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top