Print

Print


I had no luck with your script.
But this formula works in google sheets

=SUMPRODUCT(N(TEXT(ROW(INDIRECT(B2&":"&EOMONTH(B2,0))),"ddd")="Sun"))

In that formula B2 is todays date. "sun" is the day of the week I want to
measure.

Here is another example


=SUMPRODUCT(N(TEXT(ROW(INDIRECT(Today()&":"&EOMONTH(Today(),0))),"ddd")="Fri"))

that gives me a result of 3.

I'd say skip the script and use the built in functions


Good luck.

Mike.

On Thu, Mar 16, 2017 at 3:21 PM Charlie MacFadyen <[log in to unmask]>
wrote:

> Nic,
> Rather than passing today's date into the function, you can just use new
> Date().  JavaScript will create a new Date object based on the current
> time.  Documentation is here
> <https://www.w3schools.com/jsref/jsref_obj_date.asp>.
>
> Pasting in a version I got to work (I think!)
>
> _________________________________________________________
>
> function test(){
>  Logger.log(specificDaysLeft("Monday"));
>
> }
> function specificDaysLeft(dayName) {
>
>   // set day names
>   var dayNames = ["Sunday", "Monday", "Tuesday", "Wednesday",
>     "Thursday", "Friday", "Saturday"
>   ];
>
>   // establish variables
>   todaysDate = new Date();
>   var year = todaysDate.getYear();
>   var month =todaysDate.getMonth();
>   var today = todaysDate.getDate();
>
>
>   // change dayName string to index of array
>   var day = dayNames.indexOf(dayName);
>
>   // determine the number of days in current month
>   var daysinMonth = new Date(year, month+1, 0).getDate();
>   Logger.log(daysinMonth);
>
>
>
>
>
>   // set counter
>   var sumDaysLeft=0;
>
>   // iterate over the days and compare to day
>   for(var i=today; i<=daysinMonth; i++) {
>     var checkDay = new Date(year, month-1, parseInt(i)).getDay();
>     if(day == checkDay) {
>       sumDaysLeft ++;
>     }
>   }
>
>   // show amount of day names in month
>   return sumDaysLeft;
> }
>
> Charlie MacFadyen
> Technology Integration Specialist
> Champlain Valley Union HS
> 369 CVU Rd., Hinesburg, VT, 05461
> (802) 482-7117
>
> On Thu, Mar 16, 2017 at 2:19 PM, Brian Brumley <[log in to unmask]> wrote:
>
> Nic,
>
> The following would be the formula in a Google Spreadsheet:
>
> =countif(B2:B10, "Monday") ...with B2:B10 being the range for the day.
>
> Not too experienced on what looks like Java (from your example), I'm more
> of a Python guy.
>
> Good Luck!
> -Brian
>
> On Thu, Mar 16, 2017 at 2:01 PM, Phillips, Nic <[log in to unmask]>
> wrote:
>
> Hey Folks,
>
> I anyone out there proficient with Google Apps Scripts? I am having a
> problem with one that I'm working on and just can't seem to figure out
> where the issue is.  The script I'm referencing below can be viewed at:
>
>
> https://script.google.com/d/1kenzklXLu_yZz2ZAt_nhwx2nOL3wi407pzQl6incA-ay2sRVCzDNJkJG/edit?usp=sharing
>
> My goal is to use this script in a spreadsheet to calculate how many
> instances of a particular day are remaining in the current month and return
> it as a numeric value.  For example, as of today, there are exactly 2
> Mondays remaining in this month. Within a spreadsheet cell, the script
> would be called using the format *=specificDaysLeft(Today(), "Monday")*.
>
> Currently, the script seems to return a value of 4, regardless of which
> day of the week I enter into it. I've been staring at this code long
> enough to go cross-eyed and I'm sure it's something really simple causing
> this problem, but I'm burnt out trying to find it. Can anyone give it a
> look and let me know if they spot the problem?
>
> Thanks!
>
> *Nic Phillips*
> *Educational Technology Specialist*
> *Oxbow High School*
> *P: 802.222.5214 <(802)%20222-5214> - ext.147*
>
> *CONFIDENTIALITY NOTE:* The information transmitted, including
> attachments, is intended only for the person(s) or entity to which it is
> addressed and may contain confidential and/or privileged material. Any
> review, retransmission, dissemination or other use of, or taking of any
> action in reliance upon this information by persons or entities other than
> the intended recipient is prohibited. If you received this in error, please
> contact the sender and destroy any copies of this information.
>
> -----------------------------------------------------------------------
>
> Search <http://list.uvm.edu/archives/school-it.html> the SCHOOL-IT Archive
>
> Manage <http://list.uvm.edu/cgi-bin/wa?SUBED1=SCHOOL-IT&A=1> your
> Subscription to SCHOOL-IT
>
>
>
>
> --
> Brian Brumley
> Technology Integration Specialist
> [log in to unmask]
> Charlotte Central School
> 408 Hinesburg Road,  VT 05445
> http://www.ccsvt.us/
> Cell (843)343-6248 <(843)%20343-6248>
>
>
> -----------------------------------------------------------------------
>
> Search <http://list.uvm.edu/archives/school-it.html> the SCHOOL-IT Archive
>
> Manage <http://list.uvm.edu/cgi-bin/wa?SUBED1=SCHOOL-IT&A=1> your
> Subscription to SCHOOL-IT
>
>
> -----------------------------------------------------------------------
>
> Search <http://list.uvm.edu/archives/school-it.html> the SCHOOL-IT Archive
>
> Manage <http://list.uvm.edu/cgi-bin/wa?SUBED1=SCHOOL-IT&A=1> your
> Subscription to SCHOOL-IT
>