PHP – Number of Days in a Month

When we write a web application using php that deals with date we usually need to find out the number of days in a month. Using PHP you can easily calculate the number of days in a month using PHP  strtotime() function, all you have to do is to pass the desire month as argument to strtotime function and then use the date function, with the “t” placeholder.

Here is how it works:

$timestamp = strtotime("April");
$days = date("t", $timestamp); 
echo $days; // 30

Leave a Reply