Download MetaTrader 5
To add comments, please log in or register
Sign up for MQL5.community to leave your comments!
kkjawz
352
kkjawz 2014.06.29 07:57 

I know day of week returns today https://docs.mql4.com/dateandtime/dayofweek

How do I get yesterday day of week ? 

Drazen Penic
2404
Drazen Penic 2014.06.29 08:43  

Here is one idea:

      int day = DayOfWeek();
      return( day > 0 ? day-1 : 6);   
Drazen Penic
2404
Drazen Penic 2014.06.29 08:46  

And another one:

 

return( TimeDayOfWeek( LocalTime()-86400 ));  // Substract one day (86400 secs) from current local time)
Boeing747
241
Boeing747 2014.06.29 09:10  
   string f;
   switch(TimeDayOfWeek(TimeLocal()-86400))
     {
      case 1: f="MONDAY";    break;
      case 2: f="TUESDAY";   break;
      case 3: f="WEDNESDAY"; break;
      case 4: f="THURSDAY";  break;
      case 5: f="FRIDAY";    break;
      case 6: f="SATURDAY";  break;
      case 0: f="SUNDAY";    break;
     }

   Alert(f);
whroeder1
13609
whroeder1 2014.06.29 12:28  
drazen64: And another one:
return( TimeDayOfWeek( LocalTime()-86400 ));  // Substract one day (86400 secs) from current local time)
Probably don't want to do that. -86400 (or -PERIOD_D1*60) doesn't account for weekends or market holidays.
#define HR2400 (PERIOD_D1 * 60)  // 86400 = 24 * 3600
int      TimeOfDay(datetime when=0){      if(when == 0)  when = TimeCurrent();
                                          return( when % HR2400 );            }
datetime DateOfDay(datetime when=0){      if(when == 0)  when = TimeCurrent();
                                          return( when - TimeOfDay(when) );   }
//datetime Tomorrow( datetime when=0){      if(when == 0)  when = TimeCurrent();
//                                          return(DateOfDay(when) + HR2400);   }
datetime Yesterday(datetime when=0){      if(when == 0)  when = TimeCurrent();
   int iD1 = iBarShift(NULL, PERIOD_D1, DateOfDay(when) - 1);
                                       return( iTime(NULL, PERIOD_D1, iD1) ); }
/
To add comments, please log in or register