Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3761580
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T10:38:52+00:00 2026-05-19T10:38:52+00:00

I’m trying to find if a date is Monday. To do this I proceed

  • 0

I’m trying to find if a date is Monday.

To do this I proceed this way :

#define kDateAndHourUnitsComponents NSYearCalendarUnit | NSMonthCalendarUnit | NSDayCalendarUnit | NSHourCalendarUnit | NSMinuteCalendarUnit | NSSecondCalendarUnit
NSCalendar *calendar = [NSCalendar autoupdatingCurrentCalendar];

// for test and debug purpose
NSDateComponents* b = [calendar components:kDateAndHourUnitsComponents fromDate:retDate];
int a=[[calendar components:kDateAndHourUnitsComponents fromDate:theDate] weekday];
// -----------

if ([[calendar components:kDateAndHourUnitsComponents fromDate:theDate] weekday] == EKMonday) DoThis....

But this doesn’t work… a and b does not contain anything useful (a equals 2147483647),

I also wonder what can be the use of [calendar components:NSWeekdayCalendarUnit fromDate:retDate] that is not useful anymore in that case…

I also found this that confirms the process :
How to check what day of the week it is (i.e. Tues, Fri?) and compare two NSDates?

What did I miss ?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-19T10:38:53+00:00Added an answer on May 19, 2026 at 10:38 am

    Here ya go, this works and returns days via ints: 7 = Sat, 1 = Sun, 2 = Mon…

    OBJECTIVE C

    NSDate* curDate = [NSDate date];
    int dayInt = [[[NSCalendar currentCalendar] components: NSWeekdayCalendarUnit fromDate: curDate] weekday];
    

    SWIFT 4.2

    Build up the date you want to check what day of the week it is

    let dateComponents = DateComponents(
        year: 2019,
        month: 2 /*FEB*/,
        day: 23 /*23rd day of that month */
    )
    

    get the current calendar.

    let cal = Calendar.current
    

    now use the calendar to check if the build up date is a valid date

    guard let date = cal.date(from: dateComponents ) else {
        // The date you build up wasn't a valid day on the calendar
        return
    }
    
    //Now that your date is validated, get the day of the week
    
    let weekdayIndex = cal.component(.weekday, from: date)
    

    You’ll notice that the ‘weekdayIndex’ is an integer. If you want to make it a string, you can do something like this:

    if let weekdayName = DateFormatter().weekdaySymbols?[ weekdayIndex - 1] {
        print("The weekday for your date is :: \(weekdayName)")
    }
    

    Instead of building your own date, you are of course allowed to use let date = Date() instead to get what the current day of the week is

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text
this is what i have right now Drawing an RSS feed into the php,
I am trying to render a haml file in a javascript response like so:
I have this code to decode numeric html entities to the UTF8 equivalent character.
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.