corillo181 Posted August 1, 2007 Share Posted August 1, 2007 is the only way to find out the number of days in a month is using this functions? cal_days_in_month Quote Link to comment https://forums.phpfreaks.com/topic/62938-solved-number-of-days-in-month/ Share on other sites More sharing options...
hostfreak Posted August 1, 2007 Share Posted August 1, 2007 http://www.php.net/date ; date("t") in combination with http://www.php.net/mktime to get days in a defined month or just date("t") for days in current month. //defined month July echo date("t", mktime(0, 0, 0, 7, 0, 0)); //current month echo date("t"); Quote Link to comment https://forums.phpfreaks.com/topic/62938-solved-number-of-days-in-month/#findComment-313386 Share on other sites More sharing options...
Barand Posted August 1, 2007 Share Posted August 1, 2007 @hostfreak //defined month July echo date("t", mktime(0, 0, 0, 7, 0, 0)); Day 0 of a month is actually the last day of the previous month, so the code above gives 30 - the number of days in June. Use //defined month July echo date("t", mktime(0, 0, 0, 7, 1, 0)); Quote Link to comment https://forums.phpfreaks.com/topic/62938-solved-number-of-days-in-month/#findComment-313399 Share on other sites More sharing options...
hostfreak Posted August 1, 2007 Share Posted August 1, 2007 Ah, thanks for the info Barand. Quote Link to comment https://forums.phpfreaks.com/topic/62938-solved-number-of-days-in-month/#findComment-313402 Share on other sites More sharing options...
Barand Posted August 1, 2007 Share Posted August 1, 2007 BTW that does give an alternative way of getting the number of days in June, rather than July. i.e. get day for day 0 of following month <?php //defined month June echo date("d", mktime(0, 0, 0, 7, 0, 0)); ?> Quote Link to comment https://forums.phpfreaks.com/topic/62938-solved-number-of-days-in-month/#findComment-313410 Share on other sites More sharing options...
corillo181 Posted August 1, 2007 Author Share Posted August 1, 2007 i tried echo date("t",mktime(0,0,0,2,0,07)); for January and it gives me 31 dates for every other thing it either gives me 31 or 30 Quote Link to comment https://forums.phpfreaks.com/topic/62938-solved-number-of-days-in-month/#findComment-313413 Share on other sites More sharing options...
AndyB Posted August 1, 2007 Share Posted August 1, 2007 <?php echo "For the year ". date("Y"). "<br/>"; $year = date("Y"); // current year for ($m=1;$m<12;$m++) {; echo date("F",mktime(0,0,0,$m,1,$year)). " has "; echo date("t",mktime(0,0,0,$m,0,$year)); echo " days<br/>"; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/62938-solved-number-of-days-in-month/#findComment-313423 Share on other sites More sharing options...
Barand Posted August 1, 2007 Share Posted August 1, 2007 I'm sure you didn't mean to get these results For the year 2007 January has 31 days February has 31 days March has 28 days April has 31 days May has 30 days June has 31 days July has 30 days August has 31 days September has 31 days October has 30 days November has 31 days Quote Link to comment https://forums.phpfreaks.com/topic/62938-solved-number-of-days-in-month/#findComment-313431 Share on other sites More sharing options...
AndyB Posted August 1, 2007 Share Posted August 1, 2007 I'm sure you didn't mean to get these results No, but they were well-deserved. Quote Link to comment https://forums.phpfreaks.com/topic/62938-solved-number-of-days-in-month/#findComment-313448 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.