Creating a non-standard time-based trigger - google-apps-script

Hello to everyone and thanks for the help.
I have two different scripts, and each one needs to run automatically every 14 days at a specific hour of the day. (Yes, it's payroll-related.) I haven't seen a trigger that will do this, but then again, I may have missed something...
Anybody care to weigh in about how this can be done?

You will need to programmatically set up triggers and initialize it the first time. Create a new date with
var runTime = new Date()
and you can then simply offset the date with
runTime.setDate(runTime.getDate() + 14)
and set the exact runtime, for example
runTime.setHours(12)
runTime.setMinutes(0)
to run at 12:00 (no point in going deeper, because it will be with a 15 minute error margin as it can run as late as 12:15). Read here on how to set up the trigger.
This will simply have to be done every time you run the script. You clear the old trigger and have the function create a new one for next time. Since you work with a date object, you can also highly customize this to run for example every 10th of the month, or every second Thursday etc. Really depends on how well you know how to manipulate the date objects.

Related

How do I use VLOOKUP to fill out an hourly calendar schedule?

Rather than typing out the function I am dealing with since it is rather long and arbitrary without the columns it is referencing, I have provided a simplified mock-up of my spreadsheet here. Be sure to make a copy of it and not edit the original directly. If I need to remove this link, I will.
Essentially, I am trying to take a schedule that another party has already created and display it in an hourly calendar view according to the VLOOKUP search key. In my example linked above, I have created a classroom schedule in the Master Schedule tab that includes the room(s), subject, teacher(s), and start and end times, as well as the date. I have rooms scheduled for the current day, as well as the day before since some of the end times from the previous day go past midnight, and therefore I would like to include them in the calendar view for the current day if they run into the early morning. In that same tab, I have a VLOOKUP formula with the room number as the search key. The reason the formula is so long is because I have to account for if there are multiple rooms separated by a comma "," or forward slash "/", and it was drawn from an solution offered to another Stack Overflow question of mine. It gets the job done, but if there is a method that is not as convoluted, I'm all ears.
I would like to translate the data in the Master Schedule tab into the calendar view in the Room Schedule tab. I thought I had it worked out logically with a few IF statements, but I have struggled mightily. I realize open-ended questions like these aren't always appreciated on this platform, yet I am at a loss for how to accomplish what I am going for, especially without having the formulas take a long time to populate the calendar any time there is an update to the master schedule, so any help or a nudge in the right direction is greatly appreciated. I'm happy to clarify anything if the spreadsheet I linked or my objective is not clear.
paste in C2 cell and dra down and then to the right:
=IFERROR(FILTER('Master Schedule'!$F$2:$F&CHAR(10)&'Master Schedule'!$D$2:$D,
REGEXMATCH('Master Schedule'!$E$2:$E, "^"&$A2&"$"),
HOUR('Master Schedule'!$B$2:$B)<=HOUR(INDEX(SPLIT(C$1, "-"), 1, 1)),
HOUR('Master Schedule'!$C$2:$C)>=HOUR(INDEX(SPLIT(C$1, "-"), 1, 1)),
'Master Schedule'!$A$2:$A=TODAY()))
note: if this would be turned into one-cell arrayformula the performance of the sheet would suffer a lot hence this per-cell solution

MYSQL How to add an auto-decrement Schedule on MySql?

I am trying to do some automatic function on MySql.
I need that all arrows of a column named vipdays decrease by 1 on a daily basis.
I mean.. today the values of all arrows of the column vipdays = 30
Tomorrow all values = 29.. next day 28... and I need that this function
be automatic, that works without manually removing 1 day.
I have made some research and found some MySql Scheduler that automate
some functions but can't make it to work.
Any Ideas?
You should create EVENT that is executed once a day and enable scheduler (it is disabled by default).
It should work.
However, do you really want to do this?
You can store expire date in database instead of the number (ex: "DATE_ADD(CURDATE(), INVERVAL 30 DAYS)") and then compare it with CURDATE() to check if it is expired.

How to schedule an event in Mysql on table update?

I want to initiate an action after 7 days from the day a specific field in my database table is updated.
I can use trigger to trigger an event on update of field in the database table. But how can I make it wait for 7 days. I was looking for scheduling an Event but that can only be scheduled for specific time. Is there any way to dynamically set the schedule time?
There are 2 ways to do it:
You store in a timestamp field when the record was last updated. You schedule a regular event to be run every couple of hours. The event's code scans the table in question and does whatever needs to be done for those records those timestamp is between the lust run of the even and the current time.
If you have lots of records you need to handle such events, then this is the recommended approach. The drawback is that timing of the event may not be fully accurate, depending on how often you schedule this event to run.
Every time you update the record you create an event specifically for that record in a trigger or stored procedure that triggers in 7 days time.
This approach gives you absolute accuracy over when an event is triggered, however, if you have a large number of changes, then this solution does not scale well.
An alternative solution could be to record the time when the change was done, but instead of event triggering base your code on user interaction. So, if the user, whose data has been updated logs on then you notify him about what you want regarding those updates that were done more than 7 days ago and the events were not seen by the user.

Extract results updated in last 2 hours

I am trying to write a query to extract records updated in the last 2 hours in SQL Server 2008.
Could anyone help me write this?
select * from table where table.date1>=dateadd(hh,-2,getdate())
dateadd() function lets you subtract hours from getdate() letting you choose records updated past 2 hours
First, you have to design the table so you have a field where the time of the last change will be stored
Then, whenever you update a row, update the value in the 'last update' field. After that, you can use a script such as suggested by Vijaykumar
The downside of this method is that when a single record was changed more than once in the specified time period, you will be notified only about the time of the last update.
Another solution for tracking the updates is to read the database online transaction log file, but you'll need a third party tool for that

What happens when you set a Month Timer Trigger to fire on the 31st for a month that doesn't have 31 days?

In a Google Apps Script project, you can set a Time-driven trigger to fire on a monthly basis.
For example, on the 31st of every month.
What is the behavior if it is set to a day that does not exist in the current month?
For example, will a monthly trigger fire in February if it is set to fire on the 31st?
Will it end up firing on the last day of that month?
to be safe I wouldnt count on such undefined behaviour to continue behaving like it happens to behave today.
If you want to process things at the end of the month better set a daily trigger and first thing in the code check if its the last day of the month. Will consume very little quota to just check once a day.
Store in script properties the date you last processed to know if you need to run it or not.
I set a trigger to fire on the 31st, but there being no 31st day in November, the trigger did not fire at all.
Also, there was no execution failure notification sent.
So, Zig Mandel's suggestion would be the best way to setup a trigger for the last day of the month.
I set my trigger to fire Midnight-1am on the 1st of each month.
Since the Javascript Date.getMonth() function returns 0-11, this works great, except for January (0), has to be changed to 12...
Unless this is a REALLY time sensitive issue, it should fit your needs...