PHP - Calculating The Date Of Easter

In this tutorial we will create a Calculating The Date Of Easter using PHP. This code will display the actual easter day when user provide the year in the form. This code use a PHP POST method to launch a specific function that can display the easter date using easter_date() a php built-in function the will calculate the date for the easter day by providing a year as an argument.This is a user-friendly kind of program feel free to modify it. We will be using PHP as a scripting language that manage a database server to handle a bulk of data per transaction. It describe as an advance technology that manage both server and control-block of your machine.

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.
  1. <!DOCTYPE html>
  2. <?php
  3. ?>
  4. <html lang="en">
  5. <head>
  6. <meta charset="UTF-8" name="viewport" content="width=device-width, initial-scale=1"/>
  7. <link rel="stylesheet" type="text/css" href="css/bootstrap.css"/>
  8. </head>
  9. <body>
  10. <nav class="navbar navbar-default">
  11. <div class="container-fluid">
  12. <a class="navbar-brand" href="https://sourcecodester.com">Sourcecodester</a>
  13. </div>
  14. </nav>
  15. <div class="col-md-3"></div>
  16. <div class="col-md-6 well">
  17. <h3 class="text-primary">PHP - Calculating The Date Of Easter</h3>
  18. <hr style="border-top:1px dotted #ccc;"/>
  19. <div class="col-md-4">
  20. <form method="POST">
  21. <div class="form-group">
  22. <select name="year" class="form-control" required="required">
  23. <option value="">Select an option</option>
  24. <?php
  25. $y = date("Y");
  26. for($i = $y; $i >= 1965; $i--){
  27. echo "<option value='".$i."'>".$i."</option>";
  28. }
  29. ?>
  30. </select>
  31. </div>
  32. <center><button class="btn btn-primary" name="get">Get Easter Date</button></center>
  33. </form>
  34. </div>
  35. <div class="col-md-8">
  36. <?php include 'display_easter.php'?>
  37. </div>
  38.  
  39. </div>
  40. </body>
  41. </html>

Creating the Main Function

This code contains the main function of the application. This code will display the actual easter date when the button is clicked. To do that just copy and write this block of codes inside the text editor, then save it as display_easter.php.
  1. <?php
  2. if(ISSET($_POST['get'])){
  3. $year = $_POST['year'];
  4. echo "<h2>The actual date is:</h2>";
  5. echo "<center><h3 class='text-primary'>".get_easter($year)."</h3></center>";
  6. }
  7.  
  8.  
  9. function get_easter($year){
  10. $date = date("F d, Y", easter_date($year));
  11.  
  12. return $date;
  13. }
  14. ?>
There you have it we successfully created Calculating The Date Of Easter 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!

Add new comment