I need help with comparing datetime

 
I'm trying to get my EA to run only during certain hours.. I am comparing time current with an assigned date time variable.. it seems to be a logical way.. but I'm having trouble with the date part of it.. is there a way to return current date with a set time to a datetime variable..
Or if there is any other way you can recommend to accomplish this..
 
Chrissayman:
I'm trying to get my EA to run only during certain hours.. I am comparing time current with an assigned date time variable.. it seems to be a logical way.. but I'm having trouble with the date part of it.. is there a way to return current date with a set time to a datetime variable..
Or if there is any other way you can recommend to accomplish this..

simple function to access hour in the TimeCurrent():

int hour()

{

   MqlDateTime stm;

   datetime dt = TimeCurrent(stm);

   return stm.hour;

}

 
Yashar Seyyedin #:

simple function to access hour in the TimeCurrent():

int hour()

{

   MqlDateTime stm;

   datetime dt = TimeCurrent(stm);

   return stm.hour;

}

THANK YOU!!!!!
 
Yashar Seyyedin #: simple function to access hour in the TimeCurrent():
int hour(){ return TimeCurrent() / 3600 % 24; }

When dealing with time, a lot of people use strings; they can not be optimized. Using (int) seconds or (double) hours and fraction can be inputs.

See also Dealing with Time (Part 1): The Basics - MQL5 Articles (2021.10.01)
Dealing with Time (Part 2): The Functions - MQL5 Articles (2021.10.08)
MQL5 Programming Basics: Time - MQL5 Articles (2013.04.26)