Function StrToTime causes error 4051 - page 2

 
qjol:
but u have to use "yyyy.mm.dd hh:mm" format otherwise u get error 4051
OK, you are correct, either the help in MetaEditor is wrong or there is a bug, either way it need to be reported to the Service Desk I'll report it . . . and the russian in the English help.
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"


 
RaptorUK:
OK, you are correct, either the help in MetaEditor is wrong or there is a bug, either way it need to be reported to the Service Desk I'll report it . . . and the russian in the English help.

This will work as a workaround giving the same result . . .

  datetime xxxxx = StrToTime(TimeToStr(TimeCurrent(), TIME_DATE)+" "+"21:45");

. . and no error.

 
RaptorUK:

. . and no error.


of course, it's the right format
 

what are you talking about?

   Print((string)StringToTime("21:45"));
   datetime test = StringToTime("21:45");
   Print((string)test);
   Print(TimeToString(test, TIME_MINUTES));

gives

00:01:00 Test GOLD,M15: 2014.02.12 21:45:00
00:01:00 Test GOLD,M15: 2014.02.12 21:45:00
00:01:00 Test GOLD,M15: 21:45

so what is wrong?

 
graziani:

what are you talking about?

gives

so what is wrong?

StrToTime() not StringToTime()
 
graziani:

what are you talking about?

gives

so what is wrong?


add GetLastError() u will find out
 
RaptorUK:
StrToTime() not StringToTime()


doesn't matter both are giving error 4051
 

GetLastError() gives description of error only if it happened and only if the function is using error handler.

This is no the case here, so using it has no sense.

Str vs. String, you should use the new functions as they are same as in MQL5, to have source compatibility.

Also if the results is as documented, why are you insisting on error?

 
graziani:

GetLastError() gives description of error only if it happened and only if the function is using error handler.

This is no the case here, so using it has no sense.

Str vs. String, you should use the new functions as they are same as in MQL5, to have source compatibility.

Also if the results is as documented, why are you insisting on error?

ResetLastError() before the StrToTime() call then call GetLastError() afterwards . . . StrToTime() shouldn't cause an error but it does . . . it's a bug. Something similar has already been acknowledged and fixed: https://www.mql5.com/en/forum/149475/page2
 
graziani:


Str vs. String, you should use the new functions as they are same as in MQL5, to have source compatibility.

Why would I want compatibility with mql5 ? I'm using mql4 code for MT4.