Any questions from newcomers on MQL4 and MQL5, help and discussion on algorithms and codes - page 643

 
Good day, good day, people who know about compatibility of int and datetime types, please advise. If I am not mistaken, datetime is an integer representing the number of seconds elapsed from 0 hours of January 1, 1970, then can I assign the value of TimeCurrent() to an integer variable and then compare it to a variable of datetime type?
 
Андрей:
Good afternoon, can you please advise me on the compatibility of int and datetime types, if I'm not mistaken. If I am not mistaken, datetime is an integer representing the number of seconds elapsed from 0 hours of January 1, 1970, can I assign a value of TimeCurrent() to an integer variable and then compare it to a variable of datetime type?

the date can be twice as much, byte for byte

https://www.mql5.com/ru/docs/basis/types/casting

Документация по MQL5: Основы языка / Типы данных / Приведение типов
Документация по MQL5: Основы языка / Типы данных / Приведение типов
  • www.mql5.com
Часто возникает необходимость преобразовать один числовой тип в другой. Не каждый числовой тип допустимо преобразовать в другой, допустимые преобразования в MQL5 показаны на схеме: Сплошные линии со стрелками обозначают преобразования, которые выполняются без потери информации. Вместо типа char может выступать тип bool (оба занимают в памяти 1...
 
Андрей:
Good day, good day! Can you advise me please about compatibility of int and datetime types? If I'm not mistaken, datetime is an integer representing the number of seconds elapsed from 0 hours of January 1, 1970, can I assign a value of TimeCurrent() to an integer variable and then compare it to a datetime type variable?

Yes you can, but it's better to use ulong

 
Sergey Maksiutenko:

Alas, I don't get it...

Please tell me.

This code will work in two ways

1.

#property library
#property strict
//=========================
int calc (int a,int b)export
{
int c = a + b;
return(c);
}

2.

#property library
//#property strict
//=========================
int calc (int a,int b)//export
{
int c = a + b;
return(c);
}
The video is from 2013, and at the time no thought was given to the #property strict directive.
 
Taras Slobodyanik:

the date can be twice as many bytes

https://www.mql5.com/ru/docs/basis/types/casting

Yes, I read it and since I didn't see anything there about converting datetime type to integer, I asked the question here. If the integer is of type ulong, will it have enough bytes to host the time without any loss? I will explain why this hassle. I just have a two-dimensional array that stores integer data and I need to put a date on it.
 
Андрей:
Yes, I read it and since I didn't see anything there about converting datetime type to integer, I asked the question here. And let's say if an integer is type ulong, will it have enough bytes to host the time without loss? I will explain why this hassle. I just have a two-dimensional array, which stores integer data and need to add date to it.

datetime is ulong

 
Sergey Maksiutenko:

If you mean the#property library property

I've got it checked...

Without it the library file doesn't even compile.
Vitaly Gorbunov:

I'm going to smoke so I don't write too abruptly and try to explain to you what #property strict is.

Don't bother.

I understand that you cannot help me.

I took out #property strict, I took out all the properties except#propertylibrary

nothing works.

Try plugging in my construct, find the error,

and post the correct code if that's the problem.

 
Alexey Viktorov:

This code will work in two ways

1.

2.

The video is from 2013, and at that time they didn't even think about the #property strict directive, so everything worked fine.

Alas, neither option works

 
Alexey Viktorov:

This code will work in two ways

1.

2.

The video is from 2013, and at that time they didn't even think about the #property strict directive, so everything worked fine.

You should not have corrected his code at once, the man just doesn't understand elementary compiler keys, and to write a normal code you need to know these subtleties and use documentation!

I pointed out to him that the video was very old; otherwise he would have copied it exactly as it was in the video and everything would have turned out well. But he got offended and complained, and as a result the post was deleted, while he is not even going to look into it!

 
Sergey Maksiutenko:

Alas, none of the options work

Post what you've fixed! The whole code!
Reason: