Any rookie question, so as not to clutter up the forum. Professionals, don't pass by. Nowhere without you - 6. - page 742

 
AlexeyVik:
Exactly here you need to look at.

The textbook says that a truncated datetime data value format is allowed.

I only need the time (hour+minute), not the date.

My question is. Am I correct in specifying a truncated datetime value format.

if(K1==-1502&&N==D' 19:00 ')

return;

This expression does not seem to work with me for some reason.

 
solnce600:

The textbook says that a truncated datetime data value format is allowed.

I only need the time (hour+minute), not the date.

My question is. Am I correct in specifying a truncated datetime value format.

if(K1==-1502&&N==D' 19:00 ')

return;

This expression doesn't seem to work with me for some reason.

and why not use integers
 
solnce600:

The textbook says that a truncated datetime data value format is allowed.

I only need the time (hour+minute), not the date.

My question is. Am I correct in specifying a truncated datetime value format.

if(K1==-1502&&N==D' 19:00 ')

return;

This expression doesn't seem to work with me for some reason.

Since my post is in the quote, I'll have to answer it, though I don't know if it's correct or not. I've never used such a spelling.

Oh, and there's also a misunderstanding. If N is datetime type then D' 19:00 ' is text format. Can they be compared? No. In cases of time comparisons I write

datetime dt;

// где-то присвоение значения этой переменной

if(dt == StringToTime("19:00"))


And do not forget that a truncated format when converting into datetime type will be a full time.

This comparison is possible

datetime dt;

// где-то присвоение значения этой переменной

if(TimeToStr( dt, TIME_MINUTES) == "19:00")
 
Vinin:
And why not use integers

Thank you.

So instead ofdatetime, denote data of datetimetype by int type?

 
AlexeyVik:

Since my post is in the quote, I'll have to answer that, although I don't know if that's right or not. I've never used such a spelling.

Oh, and there is one more thing that is not clear. If N is datetime type then D' 19:00 ' is a text format. Can they be compared? No. In cases of time comparisons I write


And don't forget that the truncated date format, when converted to datetime type, is already full time.

This may be a comparison.

Thank you.
 
solnce600:

Thank you.

So instead ofdatetime, denote data of datetimetype by int type?

Datetime type

Thedatetime type is intended to store the date and time as the number of seconds elapsed since January 01, 1970. It takes 8 bytes of memory.

So you can take the remainder of division by the number of seconds in hours, days or other needed time intervals. And then compare the integer with the whole

 
solnce600:

Thank you.

So instead ofdatetime, denote data of datetimetype by int type?

It's always better to use time in total number of minutes, if it is used for comparison with current time: minutes+hours*60+days*24*60+... etc. This kind of time is more convenient and unambiguous to use in your Expert Advisor,

19-00 is 19*60 minutes and 20-30 is 30+20*60

for example, current hours:

TimeHour(iTime(Symbol(),PERIOD_M1,0))

current minutes:

TimeMinute(iTime(Symbol(),PERIOD_M1,0))
 
_new-rena:

time in total minutes always works better if it is used to compare with the current time: minutes+hours*60+days*24*60+... etc. This kind of time is more convenient and unambiguous to use in an EA,

19-00 is 19*60 minutes and 20-30 is 30+20*60

for example, current hours:

current minutes:

Thank you very much.
 
Vinin:

Datetime type

Datetime is intended to store the date and time as the number of seconds elapsed since January 01, 1970. It occupies 8 bytes of memory.

So you can take the remainder of the division by the number of seconds in hours, days or other required time intervals. And then compare the integer with the whole

Thank you very much.
 
Vinin:

Datetime type

Datetime is intended to store the date and time as the number of seconds elapsed since January 01, 1970. It occupies 8 bytes of memory.

So you can take the remainder of the division by the number of seconds in hours, days or other required time intervals. And then compare the whole with the integer.

Then how do you understand their textbook example?

datetime Alfa = D'2004.01.01 00:00';

According to you, after the = sign there should be a set of digits representing the number of seconds from01.01.1970 - 01.01.2004.

Reason: