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 Like 31 Dislike
Previous forums Next forums
Other forums

IMAGE - SERVER SIDE scripting help...
How to receive pixel data of an image and buid a bitmap file on the server using the HTTP POST metho

How to show a complete textarea ??
I enter Client Case Notes notes in a textarea field on a PHP form. The field is 5 rows deep and 70 c

Is there a way to override built in php functions without APD?
I am trying to use the
rename_function()
override_function()
options that are built into

Code working in IE but not FireFox
I created a dynamic navigation list for my website based off of a table in my database. The code is

need help about
i store the value of my select statement result to an array and stored it to a variable named $fname

How to get exact 3 moths post date from today date using javascript
How to get exact 3 moths post date from today date using javascript
Please help

how to query data from website using VC?
I want to query some datum from a website,so I need a program to read data from a .csv file, and ass

Socket Server
In my following socket server, I am trying to listen to a connection through port 12345 in my web br

retrieving policy name inside the function called by this particular policy
Hi there,

I've playing around with dbms_rls package, trying to set up some security repo

Click counter to ignore traffic from search bots
I have a click counter on my site that...well, counts the number of clicks a link gets on the frontp

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