Google Sheet script - send an email reminder based on due date - javascript

I've looked around and have bits and pieces but can't put the puzzle together. I'm attempting to create a script that will send an email depending on the date. I.E. if a "response" is due on 08/30 it will send a response 2 weeks prior, 1 week prior, and the date of.
Basically I'm looking for the script to capture a range of cells, identify a due date, which will be populated in a column, match it to the current date and send out reminder emails.
The script runs but it will not send me an email.
Here is the code:
function emailAlert() {
// today's date information
var today = new Date();
var todayMonth = today.getMonth() + 1;
var todayDay = today.getDate();
var todayYear = today.getFullYear();
// 1 week from now
var oneWeekFromToday = new Date();
oneWeekFromToday.setDate(oneWeekFromToday.getDate() + 14);
var oneWeekMonth = oneWeekFromToday.getMonth() + 1;
var oneWeekDay = oneWeekFromToday.getDate();
var oneWeekYear = oneWeekFromToday.getFullYear();
// 2 weeks from now
var twoWeeksFromToday = new Date();
twoWeeksFromToday.setDate(twoWeeksFromToday.getDate() + 14);
var twoWeeksMonth = twoWeeksFromToday.getMonth() + 1;
var twoWeeksDay = twoWeeksFromToday.getDate();
var twoWeeksYear = twoWeeksFromToday.getFullYear();
// getting data from spreadsheet
var sheet = SpreadsheetApp.getActiveSheet();
var startRow = 2; // First row of data to process
var numRows = 100; // Number of rows to process
var dataRange = sheet.getRange(startRow, 1, numRows, 999);
var data = dataRange.getValues();
//looping through all of the rows
for (var i = 0; i < data.length; ++i) {
var row = data[i];
var expireDateFormat = Utilities.formatDate(
new Date(row[6]),
'ET',
'MM/dd/yyyy'
);
// email information
var subject = '';
var message =
' A grievance ' +
'\n' +
' Name: ' +
row[0] +
'\n' +
' Grievance ID: ' +
row[2] +
'\n' +
' College: ' +
row[5] +
'\n' +
' Department: ' +
row[6] +
'\n' +
' Article/Policy Violation: ' +
row[7] +
'\n' +
' Status: ' +
row[9] +
'\n' +
' Response Due Date: ' +
expireDateFormat;
//expiration date information
var expireDateMonth = new Date(row[12]).getMonth() + 1;
var expireDateDay = new Date(row[12]).getDate();
var expireDateYear = new Date(row[12]).getFullYear();
//checking for today
if (
expireDateMonth === todayMonth &&
expireDateDay === todayDay &&
expireDateYear === todayYear
) {
var subject =
'A Grievance Is Due Today: ' + row[7] + ' - ' + expireDateFormat;
MailApp.sendEmail('myemail.mail', subject, message);
Logger.log('todayyyy!');
}
//checking for 1 week from now
Logger.log('1 week month, expire month' + oneWeekMonth + expireDateMonth);
if (
expireDateMonth === oneWeekMonth &&
expireDateDay === oneWeekDay &&
expireDateYear === oneWeekYear
) {
var subject =
'A grievance is due in 1 week: ' +
row[7] +
' - ' +
expireDateFormat;
MailApp.sendEmail('myemail.mail', subject, message);
Logger.log('1 week from now');
}
//checking for 2 weeks from now
Logger.log('2 weeks month, expire month' + twoWeeksMonth + expireDateMonth);
if (
expireDateMonth === twoWeeksMonth &&
expireDateDay === twoWeeksDay &&
expireDateYear === twoWeeksYear
) {
var subject =
'A grievance is due in 2 weeks: ' +
row[7] +
' - ' +
expireDateFormat;
MailApp.sendEmail('myemail.mail', subject, message);
Logger.log('2 weeks from now');
}
}
}

Related

How to display today and 5 days with a counter and pass variables from build report down to the build alert function?

How to make "funding breakdown" show today and the next five business days without removing the “totalfunding” of just today and adding a counter to the “fundingbreakdown” so it comes out numbered?
I am passing through my variables from build report down to the build alert function, but for some reason, it is not passing the values from my variables. Why is that happening?
I appreciate your patience as this is my very first googleappscript.
function buildreport() {
const ss = SpreadsheetApp.getActive();
let data = ss.getSheetByName('February 2023').getRange("A:M").getValues();
var PrimorNonPrim = ss.getSheetByName('February 2023').getRange("A:A").getValues();
var Regionandentity = ss.getSheetByName('February 2023').getRange("B:B").getValues();
var Currency = ss.getSheetByName('February 2023').getRange("D:D").getValues();
var Amount = ss.getSheetByName('February 2023').getRange("F:F").getValues();
var RequestDate = ss.getSheetByName('February 2023').getRange("K:K").getValues();
var BankAcctCreditDate = ss.getSheetByName('February 2023').getRange("L:L").getValues();
var PayDate = ss.getSheetByName('February 2023').getRange("M:M").getValues();
let payload = buildAlert(data);
sendAlert(payload);
}
function buildAlert(data,PrimorNonPrim,Regionandentity,Currency,Amount,RequestDate,BankAcctCreditDate,PayDate) {
let today = new Date();
let filteredData = data.filter(row => {
let requestDate = new Date(row[10]);
return requestDate.getFullYear() === today.getFullYear() &&
requestDate.getMonth() === today.getMonth() &&
requestDate.getDate() === today.getDate();
});
let totalfunding = filteredData.reduce((total, row) => total + row[5], 0);
if (filteredData.length === 0) {
let fundingBreakdown = "Nothing coming up within 5 working days";
} else {
fundingBreakdown = (PrimorNonPrim + " " +"Entity" + " " + Regionandentity + " " + "Currency" + " " + Currency + " " + "Amount" + " " + Amount + " " + "Request Date" + " " + RequestDate + " " + "Bank Account Credit Date" + " " + BankAcctCreditDate + " " + "Pay Date" + " " + PayDate)}

Email Alert script to check for user to be notified - Google AppScript

I found a lot of useful stuff in this forum. I am new to GAS and JS coding in general and I cannot find a way to solve something that I am confident it's NBD.
I am attaching the code first:
function emailAlert() {
// today's date information
var today = new Date();
var todayMonth = today.getMonth() + 1;
var todayDay = today.getDate();
var todayYear = today.getFullYear();
// getting data from spreadsheet
var url = SpreadsheetApp.getActiveSpreadsheet().getUrl();
var sheet = SpreadsheetApp.openByUrl(url).getSheetByName("Assignments");
var resultssn = SpreadsheetApp.openByUrl(url).getName();
//Emails addresses
var emailJonDoe = "example#example.com"
var emailEmilyDoe = "example#example.com"
var duedatesRange = sheet.getRange("H5:H9");
var duedates = duedatesRange.getValues();
var actionitRange = sheet.getRange("C5:C9");
var actionit = actionitRange.getValues();
var prjsRange = sheet.getRange("B5:B9");
var prjs = prjsRange.getValues();
var whosRange = sheet.getRange("D5:D9");
var whos = actionitRange.getValues();
//looping through all of the rows
for (var i = 0; i < duedates.length; ++i) {
var row = duedates[i];
for (var i = 0; i < actionit.length; ++i) {
var assignmenttext = actionit[i];
for (var i = 0; i < prjs.length; ++i) {
var project = prjs[i];
for (var i = 0; i < whos.length; ++i) {
var user = whos[i];
var expireDateFormat = Utilities.formatDate(
new Date(row[i]),
'ET',
'MM/dd/yyyy'
);
// email information
var subject = '';
var message =
" One of your action items is due today. " +
'\n' +
'\n' +
' Project: ' +
project[i] +
'\n' +
'\n' +
' Action Item: ' +
assignmenttext[i] +
'\n' +
'\n' +
'Check the Tracker now !!' +
'\n' +
url;
//expiration date information
var expireDateMonth = new Date(row[i]).getMonth() + 1;
var expireDateDay = new Date(row[i]).getDate();
Logger.log("Expire date is:" + expireDateDay);
//check for JD and send email to him if true
if (
user[i] === "JD" &&
expireDateMonth === todayMonth &&
expireDateDay === todayDay
) {
var subject =
'FEG AAAAAAManagement - An action item is due today!! : ' + assignmenttext[i];
MailApp.sendEmail(emailJonDoe, subject, message);
Logger.log('todayyyy!');
}
//check for ED and send email to him if true
if (
user[i] === "ED" &&
expireDateMonth === todayMonth &&
expireDateDay === todayDay
) {
var subject =
'FEG DDDDDManagement - An action item is due today!! : ' + assignmenttext[i];
MailApp.sendEmail(emailEmilyDoe, subject, message);
Logger.log('todayyyy!');
}
}
}
}
}
}
enter image description here
This is a simple snippet that send emails for each row that contains today's date in column H.
I have a similar one already working but I would like to implement the "user" feature.
Long story short, I want the code to:
Check for for each row that contains today's date in column H.
For each of above rows, check the content of it's respective cell in column D.
If it contains JD, send email alert to JD's email. If it contains ED, send email alert to ED's email.
The email should contain row's respective cell for column C (assignmenttext) and column B (project).
AFAIK, this code is not too heavy on the server side since I only "getRange" at the beginning and most of the code runs on the client side (is this correct?).
I am not confident with which loop function to use in this case and how to implement it with my code.
I am open to any comment or suggestion. Thanks in advance to anyone who would spend some time to help me. (:
This is the sort of thing I would have done. Admittedly you have to be comfortable with dealing with arrays but it makes for a nice compact code.
The two objects emails and prefix provide a place to enter new users all in one place and simplify the code by allow you to use a single send command.
function emailAlert() {
const sentcolumn=45;//I recommend adding some column to contain and indication of when an email is already been sent.
const ss=SpreadsheetApp.getActive();
const sh=ss.getSheetByName("Assignments");
const vA=sh.getRange(5,1,5,sentcolumn).getValues();//your data went from row 5 to row 9 that is five rows
const dt=new Date();
const today=new Date(dt.getFullYear(),dt.getMonth(),dt.getDate()).valueOf();//this is a number
const emails={"JD":"jd#example.com","ED":"ed#example.com"};//emails
const prefix={"JD":"FEG AAAAAAManagement - An action item is due today!! : ","ED":"FEG DDDDDManagement - An action item is due today!! : "};//subject prefixes
vA.forEach(function(r,i){
let x=new Date(r[7]);
let duedate=new Date(x.getFullYear(),x.getMonth()+1,x.getDate()).valufOf();//this is a number
var body=Utilities.formatString('One of your action items is due today. \n\n Project: %s \n\n Action Item: %s\n\nCheck the Tracker now !!\n%s',r[1],R[2],ss.getUrl());
let subject=prefix[r[3]] + r[2];
if(today==duedate && r[sentcolumn-1]!='Sent') {
GmailApp.sendEmail(emails[r[3]],subject,body);
sh.getRange(i+5,sentcolumn).setValue('Sent');//adding something like this would keep you from sending duplicate emails by mistake
}
});
}
This could be done using a single for loop, checking data in each row:
function sendEmail() {
// today's date information
var today = new Date();
var todayMonth = today.getMonth() + 1;
var todayDay = today.getDate();
var todayYear = today.getFullYear();
Logger.log(todayDay);
// getting data from spreadsheet
var url = SpreadsheetApp.getActiveSpreadsheet().getUrl();
var sheet = SpreadsheetApp.openByUrl(url).getSheetByName("Assignments");
var resultssn = SpreadsheetApp.openByUrl(url).getName();
//Emails addresses
var emailJonDoe = "example#example.com"
var emailEmilyDoe = "example#example.com"
var lastRow = sheet.getLastRow();
var dataRange = sheet.getRange(2,1,lastRow,8).getValues();
//looping through all of the rows
for (var i = 0; i < lastRow-1; i++) {
var project = dataRange[i][1];
var assignmenttext = dataRange[i][2];
var user = dataRange[i][3];
var row = dataRange[i][7];
//expiration date information
var expireDateFormat = Utilities.formatDate(new Date(row),'ET','MM/dd/yyyy');
var expireDateMonth = new Date(row).getMonth() + 1;
var expireDateDay = new Date(row).getDate();
Logger.log("Expire date is:" + expireDateDay);
//check for expiry date
if (expireDateMonth === todayMonth && expireDateDay === todayDay) {
var subject =
'FEG AAAAAAManagement - An action item is due today!! : ' + assignmenttext;
// email information
var message =
" One of your action items is due today. " +
'\n' +
'\n' +
' Project: ' +
project +
'\n' +
'\n' +
' Action Item: ' +
assignmenttext +
'\n' +
'\n' +
'Check the Tracker now !!' +
'\n' +
url;
if (user === 'JD') {
MailApp.sendEmail(emailJonDoe, subject, message);
}
if (user === 'ED') {
MailApp.sendEmail(emailEmilyDoe, subject, message);
}
}
}
}
Running this on a sample sheet returns:
Note that I did not send emails, instead I just logged values in my test code.

Ignore Sundays from jQuery date range picker

I'm using the following jQuery date range picker library : http://longbill.github.io/jquery-date-range-picker/
I would like to remove / hide all Sundays from all date range pickers while keeping a normal behavior on the date range pickers.
I tried to do something with beforeShowDay option :
beforeShowDay: function(t) {
var valid = t.getDay() !== 0; //disable sunday
var _class = '';
// var _tooltip = valid ? '' : 'weekends are disabled';
return [valid, _class];
}
but it only "disables" all Sundays whereas I want to remove / hide them:
Here's the fiddle I'm working on : https://jsfiddle.net/maximelafarie/dnbd01do/11/
EDIT:
Updated fiddle with #Swanand code: https://jsfiddle.net/maximelafarie/dnbd01do/18/
You could do it with just a little CSS but it does leave a gap:
.week-name th:nth-child(7),
.month1 tbody tr td:nth-child(7) {
display: none;
}
Hope this helps a little.
You need do changes in two functions in your daterangepicker.js file:
createMonthHTML()
function createMonthHTML(d) { var days = [];
d.setDate(1);
var lastMonth = new Date(d.getTime() - 86400000);
var now = new Date();
var dayOfWeek = d.getDay();
if ((dayOfWeek === 0) && (opt.startOfWeek === 'monday')) {
// add one week
dayOfWeek = 7;
}
var today, valid;
if (dayOfWeek > 0) {
for (var i = dayOfWeek; i > 0; i--) {
var day = new Date(d.getTime() - 86400000 * i);
valid = isValidTime(day.getTime());
if (opt.startDate && compare_day(day, opt.startDate) < 0) valid = false;
if (opt.endDate && compare_day(day, opt.endDate) > 0) valid = false;
days.push({
date: day,
type: 'lastMonth',
day: day.getDate(),
time: day.getTime(),
valid: valid
});
}
}
var toMonth = d.getMonth();
for (var i = 0; i < 40; i++) {
today = moment(d).add(i, 'days').toDate();
valid = isValidTime(today.getTime());
if (opt.startDate && compare_day(today, opt.startDate) < 0) valid = false;
if (opt.endDate && compare_day(today, opt.endDate) > 0) valid = false;
days.push({
date: today,
type: today.getMonth() == toMonth ? 'toMonth' : 'nextMonth',
day: today.getDate(),
time: today.getTime(),
valid: valid
});
}
var html = [];
for (var week = 0; week < 6; week++) {
if (days[week * 7].type == 'nextMonth') break;
html.push('<tr>');
for (var day = 0; day < 7; day++) {
var _day = (opt.startOfWeek == 'monday') ? day + 1 : day;
today = days[week * 7 + _day];
var highlightToday = moment(today.time).format('L') == moment(now).format('L');
today.extraClass = '';
today.tooltip = '';
if (today.valid && opt.beforeShowDay && typeof opt.beforeShowDay == 'function') {
var _r = opt.beforeShowDay(moment(today.time).toDate());
today.valid = _r[0];
today.extraClass = _r[1] || '';
today.tooltip = _r[2] || '';
if (today.tooltip !== '') today.extraClass += ' has-tooltip ';
}
var todayDivAttr = {
time: today.time,
'data-tooltip': today.tooltip,
'class': 'day ' + today.type + ' ' + today.extraClass + ' ' + (today.valid ? 'valid' : 'invalid') + ' ' + (highlightToday ? 'real-today' : '')
};
if (day === 0 && opt.showWeekNumbers) {
html.push('<td><div class="week-number" data-start-time="' + today.time + '">' + opt.getWeekNumber(today.date) + '</div></td>');
}
if(day == 0){
html.push('<td class="hideSunday"' + attributesCallbacks({}, opt.dayTdAttrs, today) + '><div ' + attributesCallbacks(todayDivAttr, opt.dayDivAttrs, today) + '>' + showDayHTML(today.time, today.day) + '</div></td>');
}else{
html.push('<td ' + attributesCallbacks({}, opt.dayTdAttrs, today) + '><div ' + attributesCallbacks(todayDivAttr, opt.dayDivAttrs, today) + '>' + showDayHTML(today.time, today.day) + '</div></td>');
}
}
html.push('</tr>');
}
return html.join('');
}
In this function i have added class hideSunday while pushing the element.
The 2nd function is getWeekHead():
function getWeekHead() {
var prepend = opt.showWeekNumbers ? '<th>' + translate('week-number') + '</th>' : '';
if (opt.startOfWeek == 'monday') {
return prepend + '<th>' + translate('week-1') + '</th>' +
'<th>' + translate('week-2') + '</th>' +
'<th>' + translate('week-3') + '</th>' +
'<th>' + translate('week-4') + '</th>' +
'<th>' + translate('week-5') + '</th>' +
'<th>' + translate('week-6') + '</th>' +
'<th class="hideSunday">' + translate('week-7') + '</th>';
} else {
return prepend + '<th class="hideSunday">' + translate('week-7') + '</th>' +
'<th>' + translate('week-1') + '</th>' +
'<th>' + translate('week-2') + '</th>' +
'<th>' + translate('week-3') + '</th>' +
'<th>' + translate('week-4') + '</th>' +
'<th>' + translate('week-5') + '</th>' +
'<th>' + translate('week-6') + '</th>';
}
}
In this file, I have added class to week-7 header.
CSS:
.hideSunday{display:none;}
Please note, I have not checked all the scenario but it will do trick for you.
I finally ended up by letting the Sundays appear (but completely disabling them).
These questions inspired me :
Moment.js - Get all mondays between a date range
Moment.js: Date between dates
So I created a function as follows which returns an array that contains the "sundays" (or whatever day you provide as dayNumber parameter) in the date range you selected:
function getDayInRange(dayNumber, startDate, endDate, inclusiveNextDay) {
var start = moment(startDate),
end = moment(endDate),
arr = [];
// Get "next" given day where 1 is monday and 7 is sunday
let tmp = start.clone().day(dayNumber);
if (!!inclusiveNextDay && tmp.isAfter(start, 'd')) {
arr.push(tmp.format('YYYY-MM-DD'));
}
while (tmp.isBefore(end)) {
tmp.add(7, 'days');
arr.push(tmp.format('YYYY-MM-DD'));
}
// If last day matches the given dayNumber, add it.
if (end.isoWeekday() === dayNumber) {
arr.push(end.format('YYYY-MM-DD'));
}
return arr;
}
Then I call this function in my code like that:
$('#daterange-2')
.dateRangePicker(configObject2)
.bind('datepicker-change', function(event, obj) {
var sundays = getDayInRange(7, moment(obj.date1), moment(obj.date1).add(selectedDatesCount, 'd'));
console.log(sundays);
$('#daterange-2')
.data('dateRangePicker')
.setDateRange(obj.value, moment(obj.date1)
.add(selectedDatesCount + sundays.length, 'd')
.format('YYYY-MM-DD'), true);
});
This way, I retrieve the amount of sundays in the date range I selected. For example, if there's two sundays in my selection (with sundays.length), I know I have to set two additional workdays to the user selection (in the second date range picker).
Here's the working result:
With the above screenshot, you can see the user selected 4 workdays (5 with sunday but we don't count it). Then he click on the second calendar and the 4 workdays automatically apply.
Here's the result if the period apply over a sunday (we add one supplementary day and Xfor X sundays in the period):
Finally, here's the working fiddle: https://jsfiddle.net/maximelafarie/dnbd01do/21/
I want to thank any person that helped me. The question was hard to explain and to understand.
You can also do it by setting a custom css class and use it in beforeShowDay like below
.hideSunDay{
display:none;
}
beforeShowDay: function(t) {
var valid = t.getDay() !== 0; //disable sunday
var _class = t.getDay() !== 0 ? '' : 'hideSunDay';
// var _tooltip = valid ? '' : 'weekends are disabled';
return [valid, _class];
}
But it only hides the sundays beginning from current day.
Here is a working fiddle
https://jsfiddle.net/dnbd01do/16/

Google Apps Script: "Missing ';' before statement"

Today is my first day using Google Apps Script. I am trying to make a script to grab weather information from the Wunderground Api and paste it into a spreadsheet.
For some reason I am getting the error message "Missing ';' before statement. (Line 34)".
I've searched for a solution but cant find why I am getting this error in my code.
//Everyday this script gets weather data from Weather Underground and records it in this spreadsheet.
cDay = 0, cTemp = 1, cHumidity = 2, cPressure=3, cSparkline=4, cConditions=5;
nCols=7;
function getTemp() {
var url = 'http://api.wunderground.com/api/' + appKey + '/conditions/q/CO/Aspen.json';
var sheet = SpreadsheetApp.getActiveSheet();
var rows = sheet.getDataRange();
var numRows = rows.getNumRows();
var response = UrlFetchApp.fetch(url);
var contentText = response.getContentText();
var conditions = Utilities.jsonParse(contentText);
var todaysConditions = conditions;
var temp = todaysConditions.current_observation.temp_c;
var humidity = todaysConditions.current_observation.relative_humidity;
var pressure = todaysConditions.current_observation.pressure_in;
var conditions = todaysConditions.response.features.conditions;
sheet.insertRowAfter(1);
var range = sheet.getRange(2,1,1, nCols);
var row = range.getValues()[0];
var d = new Date;
var month = d.getMonth() + 1;
var day = d.getDate();
var year = d.getFullYear();
var hour = d.getHours() + 1;
var minutes = d.getMinutes();
row[cDay] = month + '/' + day + '/' + year + '' + hour + ':' minutes; //here is the error
row[cTemp] = temp;
row[cHumidity] = humidity;
row[cPressure] = pressure;
row[cConditions] = conditions;
var nRows = numRows >= 10 ? 10 : numRows;
//row[cSparkline] = "=SPARKLINE(R[0]C[-3]:R[" + (nRows-1) + "]C[-3])";
range.setValues([row]);
}
Any help is appreciated
You have missed the '+' sign
row[cDay] = month + '/' + day + '/' + year + '' + hour + ':' + minutes;

Increment a value if ... Javascript

I am working on a small piece of code that looks to see if a value is equal to 'December 25 - January 9' and if it does increment the year (that I append to it) by one
However I can not figure out how to find that value. Every time I run the script it skips to the else part of the script when that value is selected.
Any guidance is appreciated
if ($('#date').val === 'December 25 - January 9') {
var startDates = $('#date').val().split(" - ");
var year = $('year').val;
var yearDec = parseInt(year, 10) + 1;
var payPdStart = startDates[0] + ' ' + year;
var payPdEnd = startDates[1] + ' ' + yearDec;
var startDate = Date.parse(payPdStart);
myStartDates = new Date(startDate);
var endDate = Date.parse(payPdEnd);
myEndDates = new Date(endDate)
while (myStartDates <= myEndDates) {
var firstCol = "<td style='border:none;'>" + myStartDates + "</td>";
$('#timeTable').append("<tr>" + firstCol + "</td>");
var newDate = myStartDates.setDate(myStartDates.getDate() + 1);
start = new Date(newDate);
}
}
else{
var startDates = $('#date').val().split(" - ");
var year = $('#year').val() ;
var payPdStart = startDates[0] + ' ' + year;
var payPdEnd = startDates[1] + ' ' + year;
var startDate = Date.parse(payPdStart);
myStartDates = new Date(startDate);
var endDate = Date.parse(payPdEnd);
myEndDates = new Date(endDate)
console.log(myStartDates);
console.log(myEndDates);
while (myStartDates <= myEndDates) {
var firstCol = "<td style='border:none;'>" + myStartDates + "</td>";
$('#timeTable').append("<tr>" + firstCol + "</td>");
var newDate = myStartDates.setDate(myStartDates.getDate() + 1);
start = new Date(newDate);
}
Problem is you are using JQuery but chexking value as in javascript
$('#date')[0].value === 'December 25 - January 9'
or
$('#date').val() === 'December 25 - January 9'
should do it.
I see two places where you used val instead of val(), you want to call the function val not access a non-existent val field
if ($('#date').val() === 'December 25 - January 9') { // <-- val()
var startDates = $('#date').val().split(" - ");
var year = $('year').val(); // <-- val()
Try this. It should work.
You have var should be var() also year should be #year
if ($('#date').val() === 'December 25 - January 9') {
var startDates = $('#date').val().split(" - ");
var year = $('#year').val();
var yearDec = parseInt(year, 10) + 1;
var payPdStart = startDates[0] + ' ' + year;
var payPdEnd = startDates[1] + ' ' + yearDec;
var startDate = Date.parse(payPdStart);
console.log(startDates);
console.log(year);
console.log(yearDec);
console.log(payPdStart);
console.log(payPdEnd);
myStartDates = new Date(startDate);
var endDate = Date.parse(payPdEnd);
myEndDates = new Date(endDate)
while (myStartDates <= myEndDates) {
var firstCol = "<td style='border:none;'>" + myStartDates + "</td>";
$('#timeTable').append("<tr>" + firstCol + "</td>");
var newDate = myStartDates.setDate(myStartDates.getDate() + 1);
start = new Date(newDate);
}
}
else{
var startDates = $('#date').val().split(" - ");
var year = $('#year').val() ;
var payPdStart = startDates[0] + ' ' + year;
var payPdEnd = startDates[1] + ' ' + year;
var startDate = Date.parse(payPdStart);
myStartDates = new Date(startDate);
var endDate = Date.parse(payPdEnd);
myEndDates = new Date(endDate)
console.log(myStartDates);
console.log(myEndDates);
while (myStartDates <= myEndDates) {
var firstCol = "<td style='border:none;'>" + myStartDates + " </td>";
$('#timeTable').append("<tr>" + firstCol + "</td>");
var newDate = myStartDates.setDate(myStartDates.getDate() + 1);
start = new Date(newDate);
}

Categories