snowman2344 Posted July 25, 2012 Share Posted July 25, 2012 Hello I am looking for help with the following function. What it does is get all the Wednesdays and Saturdays between 2 given dates. For that it works perfectly. I then use those dates with some more php to scrape a lottery site for the winning numbers and winning cash amounts. I am running into a problem when I use the function on a draw date. The lottery posts results after 11pm and if it is run before that time on the day of it returns the correct dates including the day of but the rest of my php errors because that lottery site is not updated. SO WHAT I AM LOOKING FOR is to run the function on the day of ONLY after 11pm EG If the start date = Wednesday July 11th And today = Wednesday July 25th And I run the function at 2pm in the afternoon I want the script to return the following Array ( [0] => 11 Jul 2012 [1] => 14 Jul 2012 [2] => 18 Jul 2012 [3] => 21 Jul 2012 ) If I run it after 11pm I want the function to return the following Array ( [0] => 11 Jul 2012 [1] => 14 Jul 2012 [2] => 18 Jul 2012 [3] => 21 Jul 2012 [4] => 25 Jul 2012 ) But any date before 11pm the day of return all Wednesdays and Saturdays function getDays($start,$end) { $t = new DateTime($start ."12:00"); $e = new DateTime($end ." 12:00"); if ($e == 'Today'){ } $out = array(); for (; $t<=$e; $t->modify("+1 day")) { $day = $t->format("D"); if (in_array($day, array('Wed','Sat'))) { $out[] = $t->format('d M Y'); } } return $out; } //to call function i use the following $dates = getDays($start_date, 'Today'); Thanks in advance Quote Link to comment https://forums.phpfreaks.com/topic/266233-find-wed-and-sat-only-after-11pm/ Share on other sites More sharing options...
xyph Posted July 25, 2012 Share Posted July 25, 2012 Will you ever get a $end in the future? If not, something like this will work. <?php $start = 'July 11th 2012'; $end = 'July 25th 2012'; var_dump(getDays($start, $end)); function getDays($start, $end) { $t = new DateTime($start . "12:00"); $e = new DateTime($end . " 12:00"); $out = array(); // prevent multiple date calls for speed. get current date and time list($ymd, $time) = explode(' ', date('Y-m-d G')); // check if $e is today, or later, and it's before 11PM if( $e->format('Y-m-d') == $ymd && $time < 23 ) { // Set the end date back 1 so script never sees it $e->modify('-1 day'); } for (; $t <= $e; $t->modify("+1 day")) { $day = $t->format("D"); if (in_array($day, array('Wed', 'Sat'))) { $out[] = $t->format('d M Y'); } } return $out; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/266233-find-wed-and-sat-only-after-11pm/#findComment-1364301 Share on other sites More sharing options...
snowman2344 Posted July 26, 2012 Author Share Posted July 26, 2012 Thats it thanks :D Quote Link to comment https://forums.phpfreaks.com/topic/266233-find-wed-and-sat-only-after-11pm/#findComment-1364430 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.