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;
}
No comments posted yet
Your Answer:
Login to answer
65
31
Other forums
Stumped by Third Day of Month problem
I am trying to build an algorithm that will essentially do this:
Code: [Select]$this_month = Oct
Help with Hyperlink
Hi,
What I am trying to do may be simple, I just can't get it to work. Ok...
I am usin
Change log of Cost centre change in Plant maintenance order
Hi,
How to view Change log of Cost centre in Plant maintenance order. Not visible thru 'Docume
How to form a xml form table with a single sql statement..?
Hi everyone,
I don't know if this is going to be a duplicate thread but i couldn't
What are causes of a connection-timeout with fopen()?
Hello! Here is the situation: The server I host my website on just upgraded it's PHP build from 4.4.
UPLOAD IMAGES NOT WORKING!
Hi there i have a upload script in which it uploads the picture to a folder than creates two thumbna
how to get values from $_Post with onchange="form.submit();"?
Hi, I have a form that submit to itself with a file upload field and two other hidden field values.<
Read from a text file after a specific word
Hi all.
I have a text file that looks like the one below.
I know how to open the text fi
Images in email problem
I found this script for sending emails, it works but if the email has <img src="image.jp
Multiple server callbacks (NOT POSTBACKS)
Hello,
I have 2 different javascript client side functions that are on timers. When the timers elap