Arduino MKR 1300 delay issues ouside of "loop()"

So I have this issue where apparently my Arduino always adds a few more milliseconds to the principal loop, basically, if I want to send data every 5 minutes my entries on the database that have a time format like: HH:MM:SS, will start deviating by a few millis, whichin turn after 2 hours or so the seconds will be different. Here's an example of the entry into database:

.... 2 hours later
... And so on

Now at start I thought this was data transfer time but well the time is always an increase (the microseconds padded with 0s 999999 always decrease by an average of about -38000)

In case you're wondering here is the code:

#include <MKRWAN.h>
#include "EmonLib.h"

LoRaModem modem;

String appEui = "---------------";
String appKey = "--------------";

EnergyMonitor emon1;
EnergyMonitor emon2;
EnergyMonitor emon3;

double totalWatt;
int time_running;
int sending;
int totalKW;
int DELAY = 60000;

  if (!modem.begin(EU868)) {
    Serial.println("Failed to start module");
    while (1) {}
  Serial.print("Your module version is: ");
  Serial.print("Your device EUI is: ");

  int connected = modem.joinOTAA(appEui, appKey);
  if (!connected) {
    Serial.println("Something went wrong; are you indoor? Move near a window and retry");
    while (1) {}

  emon1.current(1, 53);
  emon2.current(2, 53);
  emon3.current(3, 53);
  time_running = 0;

void loop() {
  unsigned long StartTime = millis();
  totalWatt = 0;
  unsigned long delay_send = 0;
  int sending = 0;
  double Irms1 = emon1.calcIrms(600);
  if (Irms1 < 0.3) Irms1 = 0;
  double Watt1 = Irms1 * 230;

  double Irms2 = emon2.calcIrms(600);
  if (Irms2 < 0.3) Irms2 = 0;
  double Watt2 = Irms2 * 230;

  double Irms3 = emon3.calcIrms(600);
  if (Irms3 < 0.3) Irms3 = 0;
  double Watt3 = Irms3 * 230;

  totalWatt = Watt1 + Watt2 + Watt3;
  totalKW = totalKW + totalWatt/1000;

  if (time_running == 5) { //15 para 15 mins
    double IrmsTotal = Irms1 +Irms2 + Irms3;
    String msg = "{\"id\":\"avac_aud1\",\"kW\":"+String(totalKW)+", \"current\":"+String(IrmsTotal)+"}";
    int err;
    err = modem.endPacket(true);
    if (err > 0) { 
      //message sent correctly
      time_running = 0;
      totalKW = 0;
    } else {
      time_running = 0;
 time_running = time_running + 1;
 if ((millis() - StartTime) > DELAY){
 } else{
    delay(DELAY-(millis() - StartTime));

My question is, since this time is probably the time between the end of the loop() and the start of a new loop(), is there any way to find the time between these two instances so that I can at least average them in those delay()?

Tldr. Why do you have calls to delay?

Sorry, didn't understand what you meant.

The delay() calls are so I can take readings every minute basically 60 000 - (time of reading and/or LoRa sending)

Why have you got calls to delay?

The delay() calls are so I can take readings every minute basically 60 000 - (time of reading and/or LoRa sending)

But these delay() work within the 60 seconds, but aside from those 60 seconds * 5 minutes there is also an unknown delay of about 6.8 milliseconds or so per loop(), which in 5 minutes would be 6.8*5 =34 milliseconds delay every 5 minutes and in 2.3 hours or so a 1 second delay.

this time is probably the time between the end of the loop() and the start of a new loop()

That seems unlikely... 6.8ms seems reasonable for the runtime of the code you have inside of loop() (or maybe 34ms each time it actually sends a packet. I see you have code that is supposed to take care of that - have you instrumented that code to see if it's working as expected? How long does the loop normally run? What value is delay actually being called with? What does the Arduino think the time is each time it sends a packet? Note that 6.8ms in a minute is about 0.01% accuracy - so you COULD just be at the edge of what the module can do (or what your database can do.) (one hopes for a bit better performance out of crystal, but...) Do you have another MKR module that you could try? Have you tried measuring the clock frequency "somehow"?
What AWOL means is that if you want to run every DELAYTIME, you should probably do something simlar to blinkwithoutdelay, where you update the "previousMillis" based on the previous previousmillis instead of whatever it happens to be now...