# Calculate How Many Days in A Month Using PHP – Info PHP

Introduction

In this article I explain the “cal__in_month()” function in PHP. This function returns the number of the in a month for the given year and calendar.

Use of this function

You can easily determine how many days are in the month and you can determine the days of any month.

Syntax

 Cal_days_in_month(calendar , month , year);

 Parameter Description Calendar Calendar to use for calculation. Month Month in select calendar. Year Year in select calendar.

Returns the length in days of the selected month in the given calendar.

Example

1. \$cal = cal_days_in_month(CAL_GREGORIAN, 5, 2013);
2. echo “There was \$cal days in may 2013”;
3. ?>

Output

Example

1. \$cal = cal_days_in_month(CAL_GREGORIAN, 11, 2011);
2. echo “There was \$cal days in november 2011”;
3. ?>

Output

Next I will explain how many days are in the month without using any calendar and determine the days used by the date function. But you will use these techniques to determine the current days of the month.

Example

1. “-//W3C//DTD XHTML 1.0 Transitional//EN” “http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd”>
2. “http://www.w3.org/1999/xhtml”>
3.
4. “Content-Type” content=“text/html; charset=iso-8859-1” />
5. How many days in the month
6.
7.
8. date_default_timezone_set(‘america/new_york’);
9. \$mnth_name = date(‘F’);
10. echo

The month is ‘\$mnth_name .

;

11. echo

Therefore ‘;

12. \$mnth = date(‘n’);
13. if(\$mnth==1)
14. {
15. echo ‘days is 31’;
16. }
17. if(\$mnth==2)
18. {
19. echo ‘days is 28 unless it is a leap year’;
20. }
21. if(\$mnth==3)
22. {
23. echo ‘days is 30’;
24. }
25. if(\$mnth==4)
26. {
27. echo ‘days is 30’;
28. }
29. if(\$mnth==5)
30. {
31. echo ‘days is 31’;
32. }
33. if(\$mnth==6)
34. {
35. echo ‘days is 29’;
36. }
37. if(\$mnth==7)
38. {
39. echo ‘days is 31’;
40. }
41. if(\$mnth==8)
42. {
43. echo ‘days is 31’;
44. }
45. if(\$mnth==9)
46. {
47. echo ‘days is 30’;
48. }
49. if(\$mnth==10)
50. {
51. echo ‘days is 31’;
52. }
53. if(\$mnth==11)
54. {
55. echo ‘days is 30’;
56. }
57. if(\$mnth==12)
58. {
59. echo ‘days is 31’;
60. }
61. ?>
62.
63.

Output

Article Prepared by Ollala Corp