0

I want to know how to get LAST DAY when I just know month and year. The month is integer and year is integer too. This is the codes :

<?php
$month = 2;
$year = 15; //I don't know why after "date('y',strtotime($tanggal_awal))" I get 15 not 2015

//how to know last date ????
?>

The real source is not like this. It's very long. I want to know PROPER MANNER TO GET last day WHERE MONTH IS FEBRUARY AND YEAR IS 2015.

AndikaK
  • 137
  • 1
  • 15

2 Answers2

3

You can use the cal_days_in_month() function, the total number of days is the same as what the last day will be.

You may need to install the calendar functions in PHP, follow instructions here: http://www.php.net/manual/en/calendar.installation.php

As suggested in the comments you can also use date('t'), which doesn't require the above extension to be installed.

naththedeveloper
  • 4,503
  • 6
  • 36
  • 44
0

use this to get the number of days of the desired month...

    int cal_days_in_month ( int $calendar , int $month , int $year )

Which gives the last date of the month.

cal_days_in_month

Gourav
  • 1,765
  • 2
  • 15
  • 16