How to extract hh:mm time from time value?

 

I'd be very grateful for a little help.  I'm trying to extract the hours:minutes close time of the previous bar.

Looking at the help here https://docs.mql4.com/convert/timetostring, I think I need something like this: 

HrsMinsTime TimeToString(
       datetime LastMarketCloseTime,
       int mode=TIME_MINUTES
        );

Where

HrsMinsTime is the variable to store the hh:mm extracted value

LastMarketCloseTime is the variable to store the datetime value of the close of the previous bar (elapsed time since 00:00 a.m. of 1 January, 1970) 

However, this just gives me compilation errors, so its wrong!

Suggestions would be most welcome!  Thanks.

 
jmb:

I'd be very grateful for a little help.  I'm trying to extract the hours:minutes close time of the previous bar.



there isn't such a command/function built in in MQL4

may i ask

for what purpose do you need that

in case you really want it

you'll have to build your own function

 

If you are happy to accept the open of the current bar (rather than the close of the previous) you can use: 

   string HrsMinsTime = TimeToStr(Time[0],TIME_MINUTES);

 

Or you can try this, which takes the open of the previous bar and adds the chart period to it:

   string HrsMinsTime = TimeToStr(Time[1]+(Period()*60),TIME_MINUTES);

 (you may want to subtract 1 from the above... depends on your preference)

 

If you want that as a string you can do something like this:

 

string HourMinuteString(datetime time)
{
  return (StringFormat("%02d:%02d", TimeHour(time), TimeMinute(time)));
}

 

 This returns string in format "hh:mm" with leading zeroes if hour and minute are less than 10.

Reason: