PHP Date Exercises : Number of days of the current month
PHP date: Exercise-27 with Solution
Write a PHP script to get the number of days of the current month.
Sample Solution:
<?php
// Output the number of days for the current month
echo 'Number of days for the month of '.date('M'). ' is :' .date('t')."\n";
?>
Output:
// Output the number of days for the current month echo 'Number of days for the month of '.date('M'). ' is :' .date('t')."\n";
N.B.: The result may varry for your system date and time.
Explanation:
In the exercise above,
echo 'Number of days for the month of '.date('M'). ' is :' .date('t')."\n";: Outputs the current month's name concatenated with the total number of days in the month obtained using the "date()" function. The format specifier 'M' returns the abbreviated month name, and 't' returns the number of days in the given month.
PHP Code Editor:
Have another way to solve this solution? Contribute your code (and comments) through Disqus.
Previous: Write a PHP script to convert the number to month name.
Next: Write a PHP script to display time in a specified timezone.
What is the difficulty level of this exercise?
Test your Programming skills with w3resource's quiz.
It will be nice if you may share this link in any developer community or anywhere else, from where other developers may find this content. Thanks.
https://w3resource.com/php-exercises/php-date-exercise-27.php
- Weekly Trends and Language Statistics
- Weekly Trends and Language Statistics