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

Material Master Update through BAPI - Follow up material not updated
Hi Experts,

I am updating the material master through a custom transaction using the BAPI

Page doesn't expand for content
Hi. I've been testing a query I made. It's here http://lapr1.6te.net/inquerito.php
The page doesn

Using system() and bringing back the results
I am aware that you can use system() within PHP to execute system commands, but I was wondering if t

I need help on this PHP code
Hi everybody, I made some kind of mistake while editing the code below. As you see, at the 3 row my

Scene graph using Direct3D?
There are several C++ scene graph based packages available for OpenGl, like say OSG,

http://w

Multi Dimensional Array Append
Hi Guys

I have a function that returns a multidimentional array eg

$result = functio

TCP Sending Unsigned Char...
Hi...

I want to send over tcp/ip some data, i have the data in hexadecimal, and when i tr

Change Sort Order to Display Newest File First
Hi Guys,

I have a page that sorts the contents (PDFs) of a directory and displays them on the

Array disappearing in foreach loop
Okay, I have this problem where an array will become undefined in a foreach loop.

Here is the

PHP FTP connect doesn't work with correct login
Hi!

i am working on this test code:
Quote<?php

$ftp_ser

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