Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Calendar days condition

In the application I need to set the condition that on a certain day of the week one variable will be true. For example

if Calendar.day == monday {
 var mon = true
}

I know that this is not right. But for now I do not quite understand how days of the week are. Please help me with this

like image 584
jojiReptiloid Avatar asked Jan 22 '26 21:01

jojiReptiloid


1 Answers

Try out this. The dayInWeek string will present the current day of the week such as "Monday", or "Tuesday". The switch statement will check for what day it is, and you can perform a function when it is that subsequent day.

let date = Date()
let dateFormatter = DateFormatter()
dateFormatter.dateFormat = "EEEE"
let dayInWeek = dateFormatter.string(from: date)

    switch dayInWeek {
    case "Monday":
        print("Today is Monday")

    case "Tuesday":
        print("Today is Tuesday")


    default:
       break
   }

Of course, you'll finish it off for the rest of the days in the week.

like image 62
EJZ Avatar answered Jan 25 '26 12:01

EJZ