How to get the time portion from a DateTime variable


I want to get time portion out of datetime… please help

ie, 2017.0.15 15:30:00 to just 15:30

The idea is to close trades after 15:30. Please let me know how to achieve this.


int i_Hours   = TimeHour(TimeCurrent());
int i_Minutes = TimeMinute(TimeCurrent());
int i_Seconds = TimeSeconds(TimeCurrent());

Draw rectangle around range of bars by hours - MQL4 and MetaTrader 4 - MQL4 programming forum

Hi ksawneyh

But in MQL5, the functions you have mentioned are not avaibalble.

I want to know how to check whether the current time is greater than 15:30, for that first i have to get 15:30 out from date time


Use MqlDateTime structure.

I have to take the time from the bar…

MqlRates priceInfo[];

datetime barTime = priceInfo[0].time;

it is this barTime, i have to split to get the Hour and Minute.

Here’s what you need:

MqlDateTime barTime;
TimeToStruct(priceInfo[0].time, barTime);
int hour = barTime.hour;
int minute = barTime.min;