How substract 1 day from TimeDayOfYear() ?

 
input DateTime Date1;

if(TimeDayOfYear(Date1) == TimeDayOfYear(TimeCurrent()))
{
        Print("It is the same day");
}

if((TimeDayOfYear(Date1) -1 day) == TimeDayOfYear(TimeCurrent())){
{
        Print("It is 1 day before Today");
}

(TimeDayOfYear(Date1) -1 day) is causing error. What is correct syntax to substract 1 day from TimeDayOfYear() ?

 
Eng Keat Ang:

(TimeDayOfYear(Date1) -1 day) is causing error. What is correct syntax to substract 1 day from TimeDayOfYear() ?

Tried the following but error too :

if((TimeDayOfYear(Date1)  - (PERIOD_D1 * 60)) == TimeDayOfYear(TimeCurrent()))
 

Found the solution :

if((TimeDayOfYear(Date1 - 86400)) == TimeDayOfYear(TimeCurrent()))
{
        Print("It is 1 day before Today");
}
 
When it compare 1991.09.01 and 2021.09.02, still
Print("It is 1 day before Today");

this is so wrong lol. How to make the comparison including year and month?

 

Ok here is the solution :

if((TimeDayOfYear(Date1 - 86400)) == TimeDayOfYear(TimeCurrent()) && (TimeMonth(Date1)) == TimeMonth(TimeCurrent())  && (TimeYear(Date1)) == TimeYear(TimeCurrent()))
{
        Print("It is 1 day before Today");
}

Or

if((TimeDay(Date1 - 1 )) == TimeDay(TimeCurrent()) && (TimeMonth(Date1)) == TimeMonth(TimeCurrent())  && (TimeYear(Date1)) == TimeYear(TimeCurrent()))
{
        Print("It is 1 day before Today");
}
 
Since a value of datetime type (number of seconds since 01.01.1970) you can "round" it to number of days using modulo operator.


today = seconds - (seconds %  86400)

yesterday = today - 1


enjoy.

 
Soewono Effendi #:
Since a value of datetime type (number of seconds since 01.01.1970) you can "round" it to number of days using modulo operator.


yesterday = today - 1

You do not want one day ago, you want one trading day ago. Think market holidays and weekends.
          Find bar of the same time one day ago - MQL4 programming forum (2017)
 
Once upon Times 41 digit perfectly,24 hour 12 timeline day
 
Eng Keat Ang:

(TimeDayOfYear(Date1) -1 day) is causing error. What is correct syntax to substract 1 day from TimeDayOfYear() ?

input DateTime Date1;
MqlDateTime STime;
TimeToStruct(Date1,STime);
int dayIWant=STime.day_of_week-1;
 
William Roeder #:
You do not want one day ago, you want one trading day ago. Think market holidays and weekends.
          Find bar of the same time one day ago - MQL4 programming forum (2017)
Why are you trolling mql5 forums? People arent giving workshops here obviously the person is going to have to code their conditions. How are you expecting people to know their special conditions when they arent mentioning any? We all know this isnt exact code to solve everyone's exact need. He asked how to get the day before today. If he wants more than that he will have to figure it out or be more specific with his question. 
 
  1. I am not trolling anything.
  2. Just because OP said what he thinks he needs doesn't mean that is what he actually wants.
         How To Ask Questions The Smart Way. (2004)
              The XY Problem
  3. By pointing a different interpretation of his question, I may be saving him, (and others,) a long road of debugging.
Reason: