Advertisement
dumle29

next_week_by_day_name.php

Aug 31st, 2015
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.79 KB | None | 0 0
  1. <?php
  2. function dateNext($dayName)
  3. {
  4.     $timeVar = time();
  5.  
  6.     while($dayName != date("D", $timeVar) && $timeVar - time() <= 604800) // Run this loop untill we find the next day with the given weekname, or untill we've looked more than a week ahead (something went wrong)
  7.     {
  8.         $timeVar += 86400 // Add a day
  9.     }
  10.  
  11.     if($timeVar - time() > 604800) // If we looped past what would be a week, return -1
  12.     {
  13.         return -1;
  14.     }
  15.  
  16.     $seconds_since_morning = (int)date("s", $timeVar) + (int)date("i", $timeVar); * 60 +  (int)date("G", $timeVar) * 60 * 60; // Use the date function to get the time in hours minutes and seconds, and convert to seconds
  17.  
  18.     return $timeVar - $seconds_since_morning; // Return the Unix timestamp for 00:00:00 on the next occurance of the date
  19. }
  20. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement