add day to datetime variable

Back to topics list To post a new topic, please log in or register
avatar
17
masoud0455_a 2016.06.20 02: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;
avatar
1223
FMIC 2016.06.20 08: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_;
avatar
17
masoud0455_a 2016.06.20 17:53 #
 
thanks a lot dear Fernando
Back to topics list  

To add comments, please log in or register