PHP - Get Total Days In A Month
Submitted by razormist on Saturday, November 9, 2019 - 17:35.
In this tutorial we will create a Get Total Days In A Month using PHP. This code will get the total days in a month when user submit the required information. The code itself use a PHP POST method to initiate a function that get the total days in a month using cal_days_in_month() by setting the required parameter in order to display the result. This is a user-friendly kind of program, feel free to use it and modify it as your own.
We will be using PHP as a scripting language and interpreter that is used primarily on any webserver including xamp, wamp, etc. It is being use to any famous websites and it has a modern technology that can easily be use by the next generation.
There you have it we successfully created a Get Total Days In A Month using PHP. I hope that this simple tutorial help you to what you are looking for. For more updates and tutorials just kindly visit this site. Enjoy Coding!
Getting Started:
First you have to download & install XAMPP or any local server that run PHP scripts. Here's the link for XAMPP server https://www.apachefriends.org/index.html. And, this is the link for the bootstrap that i used for the layout design https://getbootstrap.com/.Creating The Interface
This is where we will create a simple form for our application. To create the forms simply copy and write it into your text editor, then save it as index.php.- <!DOCTYPE html>
- <html lang="en">
- <head>
- <meta charset="UTF-8" name="viewport" content="withd=device-width, initial-scale=1"/>
- <link rel="stylesheet" type="text/css" href="css/bootstrap.css"/>
- </head>
- <body>
- <nav class="navbar navbar-default">
- <div class="container-fluid">
- <a class="navbar-brand" href="https://sourcecodester.com">Sourcecodester</a>
- </div>
- </nav>
- <div class="col-md-3"></div>
- <div class="col-md-6 well">
- <h3 class="text-primary">PHP - Get Total Days In A Month</h3>
- <hr style="border-top:1px dotted;"/>
- <div class="col-md-4">
- <form method="POST" action="">
- <div class="form-group">
- <label>Month</label>
- <select class="form-control" name="month" required="required">
- <option value="">Select month</option>
- <?php
- $months = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'];
- for($i = 1; $i<=12; $i++){
- echo "<option value='".$i."'>".$months[$i - 1]."</option>";
- }
- ?>
- </select>
- </div>
- <div class="form-group">
- <label>Year</label>
- <select class="form-control" name="year" required="required">
- <option value="">Select year</option>
- <?php
- for($y = $year; $y>=1965; $y--){
- echo "<option value='".$y."'>".$y."</option>";
- }
- ?>
- </select>
- </div>
- <center><button name="get" class="btn btn-primary">Total Days</button></center>
- </form>
- </div>
- <div class="col-md-8">
- <?php include 'get_total_days.php'?>
- </div>
- </div>
- </body>
- </html>
Creating the Main Function
This code contains the main function of the application. This code will get the total days in a month when the button is clicked. To make this just copy and write these block of codes below inside the text editor, then save it as get_total_days.php- <?php
- $month = $_POST['month'];
- $year = $_POST['year'];
- $months = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'];
- echo "<center><h2>Total of <span class='text-danger'>".$calculate."</span> days in <span class='text-success'>".$months[$month - 1]." ".$year."</span><h2></center>";
- }
- ?>
Add new comment
- 173 views