DateTime to Time

 

Hi

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.


Thanks

 
algo7134:

Hi

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.


Thanks


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


Hi Denis


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


Thanks

Satheesh

 
algo7134:

Hi Denis


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


Thanks

Satheesh

Use MqlDateTime structure.

https://www.mql5.com/en/docs/constants/structures/mqldatetime
Documentation on MQL5: Standard Constants, Enumerations and Structures / Data Structures / Date Type Structure
Documentation on MQL5: Standard Constants, Enumerations and Structures / Data Structures / Date Type Structure
  • www.mql5.com
Standard Constants, Enumerations and Structures / Data Structures / Date Type Structure - Reference on algorithmic/automated trading language for MetaTrader 5
 

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.

 
algo7134:

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.

  1. Use reply if you are posting a comment in reply to another post.
  2. Use SRC when you are pasting source code.
  3. Please spend time reading replies and MQL5 documentation and also provided links.

Here's what you need:

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