Download MetaTrader 5

Function StrToTime causes error 4051 - page 4

To add comments, please log in or register
qjol
3243
qjol  
WHRoeder:
The mq4 documents have been updated. They are both in mt4. https://docs.mql4.com/convert/StrToTime and https://docs.mql4.com/convert/stringtotime

Yep, but still gives error code 4051 unless using full format ("yyyy.mm.dd hh:mi")
whroeder1
14772
whroeder1  
RaptorUK:'s workaround
datetime StrToday(string tod){ // "21:45"
  datetime now   = TimeCurrent();
  string   today = TimeToStr(now, TIME_DATE);
  return( StrToTime(today + " " + tod) );
}
Alain Verleyen
Moderator
31180
Alain Verleyen  
qjol:

Yep, but still gives error code 4051 unless using full format ("yyyy.mm.dd hh:mi")
Is it reported to ServiceDesk ?
qjol
3243
qjol  
angevoyageur:
Is it reported to ServiceDesk ?

i dont think so (it's posted here on B604 or so & now on B610 still need to be fixed)
Simon Gniadkowski
Moderator
18003
Simon Gniadkowski  
angevoyageur:
Is it reported to ServiceDesk ?

Yes, I was as negative as I could be so I reported it out of spite . . .

Error 4051 again, this time with StrToTime
Errors, MetaTrader 4, Open, Start: 2014.02.12 22:13, #954526

Hi,

StrToTime() generates an error 4051 when just used with a time, for example StrToTime("17:35") if a date and time is used, example: StrToTime("2003.8.12 17:35") there is no error.

This can bee seen with the attached code, run it as an EA and change the input from TimeClose_ = "2003.8.12 21:45 21:45" to TimeClose_ = "21:45"


The help file shows this as an example so it should be valid . . . StrToTime("17:35"); // returns the current date with the given time

Please also note the Russian in the English help file (see below) : [in] Строка в формате "yyyy.mm.dd hh:mi ".

MQL4 Reference / Conversion Functions / StrToTime

StrToTime

Converts string in the format "yyyy.mm.dd hh:mi" to datetime type (the amount of seconds that have passed since 1 Jan., 1970).

datetime StrToTime(
string value // string
);

Parameters

value

[in] Строка в формате "yyyy.mm.dd hh:mi ".

Returned value

Value of datetime type as a number of seconds, passed since 01.01.1970.

Example:

datetime var1,var2,var3;
var1=StrToTime("2003.8.12 17:35");
var2=StrToTime("17:35"); // returns the current date with the given time
var3=StrToTime("2003.8.12"); // returns the date with the midnight time of "00:00"


Attachments:
test.mq4(1.29 KB)
Simon Gniadkowski
Moderator
18003
Simon Gniadkowski  
This was last Wednesday . . . no reply.
1234
To add comments, please log in or register