How to create a variable with yesterday's day name?


(Betty) #1

Is there a way to subtract from a system variable such as $dayOfWeekName to make the value be yesterday? How would I accomplish this? Thanks


(Alan) #2

This example assumes you are attempting to get a string variable as a result.

Not sure you can simply do Wednesday - 1 = Tuesday. However, you could create a switch statement based upon the variable $dayOfWeek = number (Example: 5). 1 = Monday.

So if Monday = 1

Switch $dayOfWeek
Case 1:
@yesterdayVariable = Sunday
Case 2:
@yesterdayVariable = Monday
etc.

Peace.


#3

Another option is to use a piston that executes daily at 23:59 (maybe a little earlier in case there is a delay executing the piston) and sets a global variable to $dayOfWeekName. That global variable will now be yesterday’s value.


(Betty) #4

For simplicity’s sake I tried this method. It’s working great, thanks for the idea!


( I hate Mondays) #5

I think there is a function to get the name of the day, and you could pass addDays($now, -1) to it. Or I think this should do the trick too:

formatDateTime(addDays($now)-1,’EEEE’)