In this topic, you explained to set a "schedule" on the last workday of the month. Now this is very nice as trigger, but I want to use this "function" in a task that runs daily.
This task should execute something when it's the last working day of the month, so it's not a trigger of schedule function, more a "if/then/else" function. In the past, you have created a script for me which counts the number of workdays.
Code: Select all
function getworkday(d,m,y)
{
workday = 0;
m--; // month begins from 0 in Javascript
dt = new Date(y, m, d);
weekday = dt.getDay();
// 0 Sunday
// 1 Monday
// 2 Tuesday
// 3 Wednesday
// 4 Thursday
// 5 Friday
// 6 Saturday
for (i=d; i>0; i--)
{
if ((weekday != 6) && (weekday != 0))
{
workday++;
}
weekday--;
if (weekday <0)
{weekday = 6;
}
}
return workday;
}
//LogMessage(getworkday(7,1,2016));
Code: Select all
function lastBusinessDayOfMonth(year, month) {
var date = new Date();
var offset = 0;
var result = null;
if ('undefined' === typeof year || null === year) {
year = date.getFullYear();
}
if ('undefined' === typeof month || null === month) {
month = date.getMonth();
}
do {
result = new Date(year, month, offset);
offset--;
} while (0 === result.getDay() || 6 === result.getDay());
return result;
}
Code: Select all
Tue May 31 00:00:00 UTC+0200 2018
Code: Select all
function lastBusinessDayOfMonth(year, month) {
var date = new Date();
var offset = 0;
var result = null;
if ('undefined' === typeof year || null === year) {
year = date.getFullYear();
}
if ('undefined' === typeof month || null === month) {
month = date.getMonth();
}
do {
result = new Date(year, month, offset);
offset--;
} while (0 === result.getDay() || 6 === result.getDay());
return result;
}
var options = { year: 'numeric', month: 'numeric', day: 'numeric' };
alert(event.toLocaleDateString('nl-NL', options));

My programming skills are very lousy, so can you adjust this script so it spits out dd-mm-yyyy?