get the value of TimeToStr()...to use it in another formula

 

hi...i have a code to find the date and time for specific bar and show them on the chart

 ObjectSetText("Firstdate",TimeToStr(Time[10],TIME_DATE|TIME_SECONDS),Fontsize,"Arial",White);

this code is ok...but i want to use the value that i got from the above code to make some calculation...

if it was an integer i can use the function 

int firstdate=TimeToStr(Time[10],TIME_DATE|TIME_SECONDS);

so i can use it in another formula or even export the value of (firstdate)   

to an excel file

but that dont work and i have only the year value  eg...2018

any help is appreciated 

 
datetime firstdate = Time[10];

The datetime data type is a lot like a ulong value. It stores the number of seconds since the epoch.

Read more here:

https://www.mql5.com/en/docs/basis/types/integer/datetime

 
Anthony Garot:

The datetime data time is a lot like a ulong value. It stores the number of seconds since the epoch.

Read more here:

https://www.mql5.com/en/docs/basis/types/integer/datetime

thanks for you

Anthony Garot....

i will take a look

regard

 
Try
 StringToTime(Time[i])
That should give you a long integer to manipulate...
 
andrew4789:
Try
 StringToTime(Time[i])
That should give you a long integer to manipulate...

Time[i] is not a string.

 

andrew4789   Keith Watford  thanks for your comments..

the problem was solved for me as the main goal is to import the date time value of a specific bar to an excel sheet 

but because am not a programmer i used the wrong  function 

int 

 but Anthony Garot gave me the correct function

datetime

which i found helpfull ...in showing the date time on the chart

and then to convert it to string in order to export it to an excel sheet

string  l_time2str_10 = TimeToStr(iTime(NULL,0, 10), TIME_DATE|TIME_MINUTES); 

sName=Symbol()+Period()+".csv";
   // int FileDelete(sName);
  int  file =FileOpen(sName,FILE_CSV|FILE_WRITE,",");
   if (file < 1) {
      Print("can not open file. error-" + GetLastError());
      return;
   } 
   
      
      FileWrite(file, l_time2str_24 );
     }
       FileClose(file);

thanks again  

Reason: