Venciity

Meeting Dates 100/100

Aug 27th, 2014
287
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.86 KB | None | 0 0
  1. <!doctype html>
  2. <html lang="en">
  3. <head>
  4.     <meta charset="UTF-8">
  5.     <title>Meeting Dates</title>
  6.     <style>
  7.         body {
  8.             font-family: tahoma;
  9.         }
  10.     </style>
  11. </head>
  12. <body>
  13. <form action="" method="get">
  14.     <input type="text" name="dateOne" value="31-12-2014"/>
  15.     <input type="text" name="dateTwo" value="01-01-2014"/>
  16.     <input type="submit" value="Submit"/>
  17. </form>
  18. <?php
  19. if (isset($_GET['dateOne']) && isset($_GET['dateTwo'])) {
  20.     date_default_timezone_set('Europe/Sofia');
  21.     $firstDate = strtotime($_GET['dateOne']);
  22.     $secondDate = strtotime($_GET['dateTwo']);
  23.     $thursDays = [];
  24.  
  25.     if ($firstDate < $secondDate) {
  26.         $currentDate = $firstDate;
  27.         while ($currentDate <= $secondDate) {
  28.             $dayOfWeek = date("N", $currentDate);
  29.             if ($dayOfWeek == 4) {
  30.                 array_push($thursDays, $currentDate);
  31.                 $currentDate = strtotime("+7 days" , $currentDate);
  32.             }
  33.             else {
  34.                 $currentDate = strtotime("+1 day" , $currentDate);
  35.             }
  36.         }
  37.     } else if ($secondDate < $firstDate) {
  38.         $currentDate = $secondDate;
  39.         while ($currentDate <= $firstDate) {
  40.             $dayOfWeek = date("N" , $currentDate);
  41.             if ($dayOfWeek == 4) {
  42.                 array_push($thursDays, $currentDate);
  43.                 $currentDate = strtotime("+7 days" , $currentDate);
  44.             }
  45.             else {
  46.                 $currentDate = strtotime("+1 day" , $currentDate);
  47.             }
  48.         }
  49.     }
  50.     if (count($thursDays) == 0) {
  51.         echo "<h2>No Thursdays</h2>";
  52.     } else {
  53.         echo "<ol>";
  54.         for($i = 0; $i < count($thursDays); $i++) {
  55.             $thursday = date("d-m-Y", $thursDays[$i]);
  56.             echo "<li>$thursday</li>";
  57.         }
  58.         echo "</ol>";
  59.     }
  60. }
  61. ?>
  62. </body>
  63. </html>
Advertisement
Add Comment
Please, Sign In to add comment