PHP - Calculating The Date Of Easter

Submitted by: 
Visitors have accessed this post 78 times.

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

And, this is the link for the bootstrap that i used for the layout design

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="<a href="">Sourcecodester</a>
  13. " rel="nofollow">">Sourcecodester</a>
  14. </a> </div>
  15. </nav>
  16. <div class="col-md-3"></div>
  17. <div class="col-md-6 well">
  18. <h3 class="text-primary">PHP - Calculating The Date Of Easter</h3>
  19. <hr style="border-top:1px dotted #ccc;"/>
  20. <div class="col-md-4">
  21. <form method="POST">
  22. <div class="form-group">
  23. <select name="year" class="form-control" required="required">
  24. <option value="">Select an option</option>
  25. <?php
  26. $y = date("Y");
  27. for($i = $y; $i >= 1965; $i--){
  28. echo "<option value='".$i."'>".$i."</option>";
  29. }
  30. ?>
  31. </select>
  32. </div>
  33. <center><button class="btn btn-primary" name="get">Get Easter Date</button></center>
  34. </form>
  35. </div>
  36. <div class="col-md-8">
  37. <?php include 'display_easter.php'?>
  38. </div>
  40. </div>
  41. </body>
  42. </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. }
  9. function get_easter($year){
  10. $date = date("F d, Y", easter_date($year));
  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

Filtered HTML

  • Web page addresses and e-mail addresses turn into links automatically.
  • You may insert videos with [video:URL]
  • Allowed HTML tags: <a> <em> <strong> <cite> <blockquote> <code> <ul> <ol> <li> <dl> <dt> <dd> <table> <tr> <td> <th> <img> <h1> <h2> <h3> <iframe> [video]
  • You can enable syntax highlighting of source code with the following tags: <code>, <blockcode>, <asp>, <c>, <cpp>, <csharp>, <css>, <html4strict>, <java>, <javascript>, <mysql>, <php>, <python>, <sql>, <vb>, <vbnet>. The supported tag styles are: <foo>, [foo].
  • Lines and paragraphs break automatically.

Plain text

  • No HTML tags allowed.
  • Lines and paragraphs break automatically.
This question is for testing whether or not you are a human visitor and to prevent automated spam submissions.