# How to get day of week for yesterday ?

Did you like the article? Share it with your friends!
352
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 ?

2545
2014.06.29 08:43

Here is one idea:

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

And another one:

return( TimeDayOfWeek( LocalTime()-86400 ));  // Substract one day (86400 secs) from current local time)
241
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;
}

14527
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) ); }