Show specific day of the week


Posted on 16th Feb 2014 07:03 pm by admin

I have been racking my brain trying to get this function to work properly and it is doing so for everything but Sundays. What I am trying to do is display all dates within a specified date range that fall within a selected day of the week (ie. Monday,etc). This function serves multiple purposes where it can be used for just one day of the week, for all weekdays, or weekends. Everything works but Sundays do not show up. Can anyone please help or suggest any other function that will accomplish what I am trying to do?

Here is the code:

function getDOW($moBeg, $dayBeg, $moEnd, $dayEnd, $year, $dayWeek) {
$week = 0;
$dayBeg = $dayBeg - 1;
$DOW = array();
$i = 1;
//Get first date of specified day from the beginning of the date range
if ($dayWeek == 0){
$week = date("w", mktime(12, 0, 0, $moBeg, $dayBeg, $year));
}
else {
while ($week != $dayWeek) { //Specify the day of the week (ie. Monday = 1)
$dayBeg++;
$week = date("w", mktime(12, 0, 0, $moBeg, $dayBeg, $year));
}
}
array_push($DOW,date("Ymd", mktime(12, 0, 0, $moBeg, $dayBeg, $year)));
$weekBeg = date("W", mktime(12, 0, 0, $moBeg, $dayBeg, $year));
$weekEnd = date("W", mktime(12, 0, 0, $moEnd, $dayEnd, $year));
while ($weekNum < $weekEnd) {
$addWeek = strtotime(date("r", mktime(12, 0, 0, $moBeg, $dayBeg, $year)) . "+" . $i . " week");
$addWeekConv = date("Ymd", $addWeek);
$weekNum = date("W", $addWeek);
if (substr($addWeekConv,0,4) == $year && substr($addWeekConv,4,2) <= $moEnd){
//Conditional fixes problem where an extra date from next month or year is added
array_push($DOW,$addWeekConv);
$i++;
}
}
return $DOW;
}

65 Like 31 Dislike
Previous php-forum Next php-forum
Other php-forum

get the country of visitor and display content based on that
Hello all,

I have seen that Google analytics can tell you where a visitor is coming from and

PHP webpage & array print issue
I have this code running, and it works perfectly … however, see my bottom bit about what I see

Passing PHP variables from one page to another
Hello-

I'm having trouble figuring out how to transport a variable from one php file to anoth

include function being weird?
I have a very simple system to grab an IP outputted by a PHP file.. (for a project I have) but it ou

How to return to a previous page after running a PHP script
I'm having a bit of a melt down here because I think this should be really easy but can't work it ou

Undefined index: username HELP NEWBIE
I am trying a simple login/logout for my website. It works well with checking if the username exists

multipart emiail forms
Hi All,

I am new to the boards and I've been working on a form (which is rather massive, imo

Quick fix: Conditional statement with an array
Hi, I'm getting the temperature value off of the Environment Canada website along with the icon file

how to insert value
I am having file bookissueadd.php..... in which i am having tag

<td height="21&q

phph within href not showing php if change ? to &
Code: [Select]<a href="<?php echo $puser; ?>?m=<?php=(($m-1)&l

Sign up to write
Sign up now if you have flare of writing..
Login   |   Register
Follow Us
Indyaspeak @ Facebook Indyaspeak @ Twitter Indyaspeak @ Pinterest RSS



Play Free Quiz and Win Cash