subtract three minutes to the current time

 

Inspired by the code in the documents, so I can go back to the current time:

string var1=TimeToStr(TimeCurrent(),TIME_DATE|TIME_SECONDS);

how can I subtract 3 minutes to the current time?


I tried to write the code so it does not work

double var2= var1 - 3;


 
fly7680: Inspired by the code in the documents, so I can go back to the current time:

how can I subtract 3 minutes to the current time?

datetime dtvar = TimeCurrent() - 180; // 3 min * 60 sec = 180 sec
 
Great thanks! 
 

I'm doing some tests with writing on my data files, but I have some problems....This is my code:


datetime var1= TimeCurrent() - 180;
string   var2= TimeToString(var1,TIME_DATE|TIME_MINUTES);



datetime time_alert;
extern bool Audible_Alerts = true;
double myPoint;

void myAlert(string type, string message)
  {
   int handle;
   if(type == "print")
      Print(message);
   else if(type == "error")
     {
      Print(type+" | RSIlevel "+Symbol()+","+Period()+" | "+message);
     }
   else if(type == "order")
     {
     }
   else if(type == "modify")
     {
     }
   else if(type == "RsiLevel")
     {
      handle = FileOpen("RSIlevel.txt", FILE_TXT|FILE_READ|FILE_WRITE|FILE_SHARE_READ|FILE_SHARE_WRITE, ';');
      if(handle != INVALID_HANDLE)
        {
         FileSeek (handle, 0, SEEK_END);
         FileWrite(handle, type+ "|" +Symbol()+ "," +var2+ "|"+message);
         FileClose(handle);
        }
     }
  }


The problem is that even by varying the seconds value to be subtracted from TimeCurrent, the final risltato is wrong. I do not understand why.

 

I think the mistake is to refresh, the first compilation of the code, the time is right, in the following signals, the time remains the same as the first.
tips to solve?

 

I should have solved including the variables within the function, confirmed to me that it's all written politely well?

void myAlert(string type, string message)
  {
  
  datetime var1= TimeCurrent() - 120;
  string   var2= TimeToString(var1,TIME_DATE|TIME_MINUTES);
  
   int handle;
   if(type == "print")
      Print(message);
   else if(type == "error")
     {
      Print(type+" | RSIlevel "+Symbol()+","+Period()+" | "+message);
     }
   else if(type == "order")
     {
     }
   else if(type == "modify")
     {
     }
   else if(type == "RsiLevel")
     {
      handle = FileOpen("RSIlevel.txt", FILE_TXT|FILE_READ|FILE_WRITE|FILE_SHARE_READ|FILE_SHARE_WRITE, ';');
      if(handle != INVALID_HANDLE)
        {
         FileSeek (handle, 0, SEEK_END);
         FileWrite(handle, type+ "|" +Symbol()+ ","+Period()+ ","+var2+ "|"+message);
         FileClose(handle);
        }
     }
  }
 
fly7680:

I should have solved including the variables within the function, confirmed to me that it's all written politely well?

You are not using "var1" or "var2" anywhere in your code! How are you using them to test or alter the functionality? You will have to show that part of the code and explain what it is you are expecting!