Download MetaTrader 5
To add comments, please log in or register
Make screenshots in MetaTrader and manage them in the gallery!
masoud0455_a
51
masoud0455_a 2016.06.20 00:12 

I want to declare an external integer variable for day and add it to a datetime variable, Is it possible?

I need some code Like this, to get for example 10 days from an external variable an add it to my datetime variable.

Should I first convert days to millisecond then add to datetime?  how can I do that? 

just help me how can I add  some days to a datetime variable...

extern int days= 10;
datetime d1= D'20.12.2016';
datetime dnew= D'20.12.2016'+ day;
Fernando Carreiro
1502
Fernando Carreiro 2016.06.20 06:17  

You should consult the documentation when in doubt: https://docs.mql4.com/basis/types/integer/datetime

Datetime Type

The datetime type is intended for storing the date and time as the number of seconds elapsed since January 01, 1970. This type occupies 8 bytes of memory.

So, first convert your "day" into "seconds" then add them:

#define   _DAYSECONDS_ 86400; // 1day = 24hr * 60min * 60sec = 86400sec

input int days = 10; // use "input" instead of "extern" to prevent changes to variable within code execution
datetime  d1   = D'20.12.2016',
          dnew = d1 + days * _DAYSECONDS_;
masoud0455_a
51
masoud0455_a 2016.06.20 15:53  
thanks a lot dear Fernando
/
To add comments, please log in or register