View Tutorial Metadata Edit Content Revision History Add to Watchlist Add New Tutorial How to find the last day of the month in PHP

How to find the last day of the month in PHP

When you are doing, for example, reports on months you need to know the last day of the month so you can calculate the needed timestamp (between the first and the last day).

As you know, for example, December has always 31 days, same for March and so on. Based on those facts a function can be easily written.

But why doing this? it seems PHP has a built-in function for it :)

// will return the last day of the current month
print date('t'); 
 
// will return the last day of the month in which that timestamp is
print date('t',TIMESTAMP);

Only plain text supported.

Optional

Required - will be kept private

Optional

 
 

Rating: (0+, 0-) In: PHP 5