date - How can I get the days of the month by using php? -


enter image description herei want display dates of respective days in particular month. how can it? manage input month , show dates.

<html>  <body>  <form method="post">  day (eg: sunday) : <input name="day" required type="text" size="30" style="height:30px;" /> <br/><br/>  month (eg: 7) : <input name="month" required type="text" size="30" style="height:30px;" /> <br/><br/>  <input name="submit" type="submit" value="log in" style="background-color: #2e9afe; border: 1px solid #084b8a;  padding: 1px 3px; color:#fff; width:60px; height:30px;" />  </form>    <?php    	$day=$_post['day'];  	$month=$_post['month'];  	      function getdates($y, $m)  	{  		return new dateperiod(  			new datetime("first sunday of $y-$m"),  			dateinterval::createfromdatestring('next sunday'),  			new datetime("last day of $y-$m")  		);  	}    	foreach (getdates(2015, $month) $getday) {  		echo $getday->format("l, y-m-d\n");  	}    	  ?>  </body>  </html>

if wish give month input iterate total number of days in month

here's eval

<?php $days=array(); $month = 8; for($d=1; $d<=31; $d++) {     $time=mktime(12, 0, 0, $month, $d, '2015');               if (date('m', $time)==$month)                $days[]=date('y-m-d-d', $time); } echo '<pre>'; print_r($days); echo '</pre>'; ?> 

note :

  1. i have given year directly can give dynamic (user's choice).

  2. the days in month given directly 31 shall find number of days , give too.

update :

as op wants monday dates.

<?php $days=array(); $month = 12; for($d=1; $d<=31; $d++) {     $time=mktime(12, 0, 0, $month, $d, '2014');               if (date('m', $time)==$month)                $day=date('d', $time);         if($day=='mon')         {         $days[]=date('y-m-d-d', $time);         } } echo '<pre>'; print_r($days); echo '</pre>'; ?> 

here's updated eval


Comments