# Check if order date is today?

14

How I can check if order day is today? I found quite ugly way . Should more elegant solution

```for (int trade = OrdersHistoryTotal() - 1; trade >= 0; trade--) {
if (OrderSelect(trade, SELECT_BY_POS, MODE_HISTORY) == true && OrderSymbol() == Symbol()
&& TimeDay(OrderOpenTime())==TimeDay(TimeCurrent())
&& TimeMonth(OrderOpenTime())==TimeMonth(TimeCurrent()) && TimeYear(OrderOpenTime())==TimeYear(TimeCurrent())

)```
1753

How I can check if order day is today? I found quite ugly way . Should more elegant solution

I don't know if this way is less ugly but you can try it:

```        if (OrderSelect(trade, SELECT_BY_POS, MODE_HISTORY) == true && OrderSymbol() == Symbol()
&& OrderOpenTime()>=TimeCurrent()-TimeCurrent()%86400)```
37447

Petr Nosek:

I don't know if this way is less ugly but you can try it:

It would be less ugly by declaring a "today" variable outside the loop, instead of calculating it each time.
1753

Alain Verleyen:
It would be less ugly by declaring a "today" variable outside the loop, instead of calculating it each time.

You are right as usual. But it was just an example and I used in that example only condition without the loop. But I can write the whole code for you.

BTW "OrderSelect(trade, SELECT_BY_POS, MODE_HISTORY) == true" is ugly too.

```   datetime today=TimeCurrent()-TimeCurrent()%86400;
if(OrderSelect(trade,SELECT_BY_POS,MODE_HISTORY) && OrderSymbol()==Symbol() && OrderOpenTime()>=today)
{

}```
37447

Petr Nosek:

You are right as usual. But it was just an example and I used in that example only condition without the loop. But I can write the whole code for you.

BTW "OrderSelect(trade, SELECT_BY_POS, MODE_HISTORY) == true" is ugly too.

`datetime today=TimeCurrent()-TimeCurrent()%86400;`

Using 2 times the same function in a row is ugly too

1753

Alain Verleyen:

Using 2 times the same function in a row is ugly too

Because of you, I won't have lunch.  Hope you're satisfied.
```   datetime today=TimeCurrent();
today-=today%86400;
if(OrderSelect(trade,SELECT_BY_POS,MODE_HISTORY) && OrderSymbol()==Symbol() && OrderOpenTime()>=today)
{

}```
37447

Petr Nosek:
Because of you, I won't have lunch.  Hope you're satisfied.
Well, as we are talking about ugliness, I am wondering why >=0 became >-1 ? ;-)
1753

Alain Verleyen:
Well, as we are talking about ugliness, I am wondering why >=0 became >-1 ? ;-)
I don't want infringe copyright :D The result is the same and I refuse to update the code ;-)
569

Alain Verleyen:
Well, as we are talking about ugliness, I am wondering why >=0 became >-1 ? ;-)
Yes... That's bullying :P