Download MetaTrader 5
To add comments, please log in or register
The entire MQL5.community history on a single page!
Samuel Ogden
228
Samuel Ogden 2014.07.24 18:31 

Hi, I need to check the time is between midnight and 12:05 (GMT +2) in an IF statement.

How could I do this??

Thanks, sam. 

qjol
3243
qjol 2014.07.24 19:04  
Samuel Ogden
228
Samuel Ogden 2014.07.24 19:40  

Thanks...

So would

if ( TimeLocal() >= '00:00:00' && TimeLocal() <= '00:05:00')

work?

 

Im new to this, cant get my head around the time functions and order functions.

Sam. 

Simon Gniadkowski
Moderator
17963
Simon Gniadkowski 2014.07.25 07:56  
samuelgo:

Thanks...

So would

if ( TimeLocal() >= '00:00:00' && TimeLocal() <= '00:05:00')

work?

 

Im new to this, cant get my head around the time functions and order functions.

Sam. 

The time functions return a datetime type variable (number of seconds since 1/1/70) so you should convert your midnight and midnight:05 times to datetimes,  have a read of this:  Midnight
Samuel Ogden
228
Samuel Ogden 2014.07.25 14:33  
Thanks!
whroeder1
13656
whroeder1 2014.07.26 00:45  
samuelgo: I need to check the time is between midnight and 12:05 (GMT +2) in an IF statement.
#define HR2400 (PERIOD_D1 * 60)  // 86400 = 24 * 3600
int      TimeOfDay(datetime when=0){      if(when == 0)  when = TimeCurrent();
                                          return( when % HR2400 );            }
datetime DateOfDay(datetime when=0){      if(when == 0)  when = TimeCurrent();
                                          return( when - TimeOfDay(when) );   }
//datetime Tomorrow( datetime when=0){      if(when == 0)  when = TimeCurrent();
//                                          return(DateOfDay(when) + HR2400);   }
//datetime Yesterday(datetime when=0){      if(when == 0)  when = TimeCurrent();
//   int iD1 = iBarShift(NULL, PERIOD_D1, DateOfDay(when) - 1);
//                                       return( iTime(NULL, PERIOD_D1, iD1) ); }
:
#define HR0005 300 // 12:05 AM
datetime now = TimeCurrent(); // or local or gmt
if(TimeOfDay(now) < HR0005) ...

honest_knave
970
honest_knave 2014.07.26 11:27  

It's not particularly elegant, but I use the following to get midnight of the current date (or whichever date you wish to substitute):

   datetime Midnight = (datetime)TimeToStr(TimeCurrent(),TIME_DATE);
/
To add comments, please log in or register