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
browse folder only
hi,
is there a way i can browse or get the directory or folder only and not the file?
i just w
php include email form with attachment
I have had no luck with finding a email form all over the Internet for various reasons. Some insecur
Logic question
im wondering what's the best method to do the above list:
it is for alliance @ MMORPG game
upload only text files
hi guys i want to upload only text like like (pdf,note pad and ofiice files) so can any one please t
Working with Global Variables
hi, I'm not really sure why the following code is returning a "Call to a member function getBan
Word Trimming
Hi Guys & Gals!!
Hope you are all ok....
I need some help with the following
PDO returns erroneous columns from within pdt
Hi All,
This is a truly weird behavior:
When using a simple pdo fetch, erroneous columns a
JSON SORT WITH PHP
I have two products that I want to sort by say "Id:17, value: xxx" using php
The page w
Saving PHP output as a file
I wondered if anyone knows how to save the rendered output of a PHP script as a file?
I have
confused between ' ' and " "
there is a php i set:
$begin_date_query = mysql_query( "SELECT SUBDATE(due_date, INTERVAL $d