add one day or remove, return 1970 .....

 

Hi i build  a  function for  remove  one  day or add one day  but  when i use it  return me always  epoch linux  time , whats wrong ?



t1 = StrToTime("2023.09.12 14:00:00");

 nuovaData = _TimeDateCalcolate(t1, "-", 1);
       Print("Nuova data: ", TimeToString(nuovaData, TIME_DATE | TIME_MINUTES | TIME_SECONDS));



datetime _TimeDateCalcolate(datetime datadipartenza, string Operazione, int giorni)
{
    if (Operazione == "+")
    {
        // Somma giorni alla data di partenza
        datadipartenza += (giorni * 86400);
    }
    else if (Operazione == "-")
    {
        // Sottrai giorni dalla data di partenza
        datadipartenza -= (giorni * 86400);
    }
    else
    {
        // Operazione non valida, restituisci la stessa data di partenza
        return datadipartenza;
    }

    return datadipartenza;
}
 

Hello

it works  , the issue is elsewhere probably , in the feed of the date on t1 likely

 
faustf:

Hi i build  a  function for  remove  one  day or add one day  but  when i use it  return me always  epoch linux  time , whats wrong ?

You can do it in 1 line of code btw and drop the whole +/- logic bc integers can have negative values, yes?

#define AddDayMacro(x,y) x += y * 86400; // x - time y - number of days

Or if you don't like macros

datetime AddDayFunction(datetime datadipartenza, int giorni) { return datadipartenza += giorni * 86400; }
 
thanks so much

 

Don't hard code numbers.
          Find bar of the same time one day ago - MQL4 programming forum #1 & #6 (2017)

datetime when= …;

datetime tomorrow = when + PeriodSeconds(PERIOD_D1);