How can I find the next weekend Swift

isdateinweekend swift
swift date
nscalendar
number of days between two dates swift
swift get next monday
swift get next day of week

I have an app in which I want to show some data when it's Saturday or Sunday. Actually I have a segmented control and if I press one of my option (which will be the weekend) I want to check If it is Saturday or Sunday but only the first weekend.

This is what I've done for my first option in segmented control to take the current date

dateevent is a variable that I take to check if is the currentDate currentDate is declared to be the currentDate

  if  dateevent.earlierDate(self.currentDate).isEqualToDate(self.currentDate){

  if NSCalendar.currentCalendar().isDate(dateevent, equalToDate: self.currentDate, toUnitGranularity: .Day){

                                //Do something
                            }

                        }

First find the number of days to add to NSDateComponents weekday property and then You can use dateByAddingComponents(_:toDate:options:).

let today = NSDate()
let calendar = NSCalendar.currentCalendar()

let todayWeekday = calendar.component(.Weekday, fromDate: today)

let addWeekdays = 7 - todayWeekday  // 7: Saturday number
var components = NSDateComponents()
components.weekday = addWeekdays

let nextSaturday = calendar.dateByAddingComponents(components, toDate: today, options: .MatchFirst)

nextWeekendStart(_:interval:options:after:), Returns by reference the starting date and time interval range of the next weekend period after a given date. SDKs. iOS 8.0+; macOS 10.9+; Mac Catalyst 13.0+  If the date does fall within a weekend, you can use the rangeOfWeekendStartDate:interval:containingDate: method to determine the start date of that weekend period. Otherwise, you can use the nextWeekendStartDate:interval:options:afterDate: method to determine the start date of the next or previous weekend.

From the Apple docs:

If the date does fall within a weekend, you can use the rangeOfWeekendStartDate:interval:containingDate: method to determine the start date of that weekend period. Otherwise, you can use the nextWeekendStartDate:interval:options:afterDate: method to determine the start date of the next or previous weekend.

isDateInWeekend(_:), method to determine the start date of the next or previous weekend. See Also. Comparing Dates. func compare  Get ready to shake off those quarantine blues with Taylor Swift. Tonight, ABC will be airing a new Taylor Swift concert on TV, City of Lover. The special event was originally filmed in September

extension for getting day of the week

func dayOfTheWeek() -> String? {
    let dateFormatter = NSDateFormatter()
    dateFormatter.locale = NSLocale(localeIdentifier: "en_US")
    dateFormatter.dateFormat = "EEEE"
    return dateFormatter.stringFromDate(self)
}

then you can just count how many days do yo need to weekend and add it to NSDate

NSDate().dateByAddingTimeInterval(60 * 60 * 24 * daysFromTodayToWeekend)

Get the date of the next Sunday? : swift, I spent my first weekend learning how to use this software. Luckily, before my first day I got a computer sent to my house and it had a list of applications I would  Find a SWIFT/BIC code. Use our BIC / SWIFT code finder to look up a SWIFT code. Search by bank or country — or search for the SWIFT code of a particular bank branch. If you’ve already got a code, you can use the BIC / SWIFT finder to check that it’s correct.

Swift 4 Solution

I have figured out according to my requirement, where I have find out dates for following.

1. Today

2. Tomorrow 

3. This Week 

4. This Weekend 

5. Next Week 

6. Next Weekend

So, I have created Date Extension to get Dates of Current Week and Next Week.

CODE

extension Date {

    func getWeekDates() -> (thisWeek:[Date],nextWeek:[Date]) {
        var tuple: (thisWeek:[Date],nextWeek:[Date])
        var arrThisWeek: [Date] = []
        for i in 0..<7 {
            arrThisWeek.append(Calendar.current.date(byAdding: .day, value: i, to: startOfWeek)!)
        }
        var arrNextWeek: [Date] = []
        for i in 1...7 {
            arrNextWeek.append(Calendar.current.date(byAdding: .day, value: i, to: arrThisWeek.last!)!)
        }
        tuple = (thisWeek: arrThisWeek,nextWeek: arrNextWeek)
        return tuple
    }

    var tomorrow: Date {
        return Calendar.current.date(byAdding: .day, value: 1, to: noon)!
    }
    var noon: Date {
        return Calendar.current.date(bySettingHour: 12, minute: 0, second: 0, of: self)!
    }

    var startOfWeek: Date {
        let gregorian = Calendar(identifier: .gregorian)
        let sunday = gregorian.date(from: gregorian.dateComponents([.yearForWeekOfYear, .weekOfYear], from: self))
        return gregorian.date(byAdding: .day, value: 1, to: sunday!)!
    }

    func toDate(format: String) -> String {
        let formatter = DateFormatter()
        formatter.dateFormat = format
        return formatter.string(from: self)
    }
}

USAGE:

let arrWeekDates = Date().getWeekDates() // Get dates of Current and Next week.
let dateFormat = "MMM dd" // Date format
let thisMon = arrWeekDates.thisWeek.first!.toDate(format: dateFormat)
let thisSat = arrWeekDates.thisWeek[arrWeekDates.thisWeek.count - 2].toDate(format: dateFormat)
let thisSun = arrWeekDates.thisWeek[arrWeekDates.thisWeek.count - 1].toDate(format: dateFormat)

let nextMon = arrWeekDates.nextWeek.first!.toDate(format: dateFormat)
let nextSat = arrWeekDates.nextWeek[arrWeekDates.nextWeek.count - 2].toDate(format: dateFormat)
let nextSun = arrWeekDates.nextWeek[arrWeekDates.nextWeek.count - 1].toDate(format: dateFormat)

print("Today: \(Date().toDate(format: dateFormat))") // Sep 26
print("Tomorrow: \(Date().tomorrow.toDate(format: dateFormat))") // Sep 27
print("This Week: \(thisMon) - \(thisSun)") // Sep 24 - Sep 30
print("This Weekend: \(thisSat) - \(thisSun)") // Sep 29 - Sep 30
print("Next Week: \(nextMon) - \(nextSun)") // Oct 01 - Oct 07
print("Next Weekend: \(nextSat) - \(nextSun)") // Oct 06 - Oct 07

You can modify Extension according to your need.

Thanks!

Finding start and end of current week (gives me the next week) : swift, So for example, in my time zone, this current week is from 17. to 23rd February. This is my current playground: extension Date { var startOfWeek: Date? { let  About Swift. Swift is a different kind of bus service that is designed to get you there fast. With Swift bus rapid transit you can hop on and off along the route to get to places in your community, or you can make connections that will take you to work, school, or play.

SwiftDate, The number of week-numbering units for the receiver. Declaration. public var yearForWeekOfYear: Int. Note. This value is interpreted in the context of the calendar  The SWIFT code can be found on a bank's website, on your bank statement, or through an online search. Make sure you copy down the correct characters when recording a SWIFT code, and check that it has 8 or 11 characters. The first 4 characters stand for the bank to which money is being transferred.

The National Provisioner, Manager T. C. Sullivan, of Swift & Com— pany's provision department in the New York district, was in Chicago this week. Swift & Company's sales of beef in  Here is how you can ask Taylor Swift out that will possibly help you avoid instant rejection: Hand-written note delivered via carrier pigeon. Taylor Swift is a romantic, and only the most romantic

This Week in Swift, Hi there, I'm @NatashaTheRobot and I'm programmed to love #Swift! Every week​, I put together a list of the best Swift resources for you,  Whether it’s a last minute trip to Seattle, a flight to Chicago or a sale on a New York City getaway, Delta has you covered. Delta serves more than 325 destinations on six continents, with many available flights wherever your journey takes you. View our current flight deals or book a flight. Popular Destinations. Start Searching.

Comments
  • Hi I tested your code and I printed the dates, It returned Saturday but when I try to compare them It compare the time too so do you know how can I compare only the date?
  • If you could help me with an example it would be great because I tried to use it but I couldn't Thanx