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 1000713
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T07:33:26+00:00 2026-05-16T07:33:26+00:00

i.e.: NSDate *firstDayOfWeek = [[NSDate date] firstDayOfWeek]; for example, today is Aug 19, I’d

  • 0

i.e.:

  NSDate *firstDayOfWeek = [[NSDate date] firstDayOfWeek];

for example, today is Aug 19, I’d want to get a NSDate of 2010-08-15 12:00am from above line of code. Thanks!

  • 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-16T07:33:27+00:00Added an answer on May 16, 2026 at 7:33 am

    I think this threads responds to what you’re looking for: http://www.cocoabuilder.com/archive/cocoa/211648-nsdatecomponents-question.html#211826

    Note however that it doesn’t handle Mondays as first days of the week, so you may have to tweek it a little by substracting [gregorian firstWeekday] instead of just 1. Also, I modified it to use -currentCalendar, but it’s up to you 🙂

    NSDate *today = [NSDate date];
    NSCalendar *gregorian = [NSCalendar currentCalendar];
    
    // Get the weekday component of the current date
    NSDateComponents *weekdayComponents = [gregorian components:NSWeekdayCalendarUnit fromDate:today];
    /*
    Create a date components to represent the number of days to subtract
    from the current date.
    The weekday value for Sunday in the Gregorian calendar is 1, so
    subtract 1 from the number
    of days to subtract from the date in question.  (If today's Sunday,
    subtract 0 days.)
    */
    NSDateComponents *componentsToSubtract = [[NSDateComponents alloc] init];
    /* Substract [gregorian firstWeekday] to handle first day of the week being something else than Sunday */
    [componentsToSubtract setDay: - ([weekdayComponents weekday] - [gregorian firstWeekday])];
    NSDate *beginningOfWeek = [gregorian dateByAddingComponents:componentsToSubtract toDate:today options:0];
    
    /*
    Optional step:
    beginningOfWeek now has the same hour, minute, and second as the
    original date (today).
    To normalize to midnight, extract the year, month, and day components
    and create a new date from those components.
    */
    NSDateComponents *components = [gregorian components: (NSYearCalendarUnit | NSMonthCalendarUnit | NSDayCalendarUnit)
                                                fromDate: beginningOfWeek];
    beginningOfWeek = [gregorian dateFromComponents: components];
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

When using NSDate to get today's date, I seem to be getting a date
I need to get an NSDate object for 00:00(beginning of the day) from [NSDate
NSDate * now = [NSDate date]; I get this date one hour earlier. Probably
I have an NSDate that I get from a UIDatepicker. IBOutlet UIDatePicker *dueDate; NSDate
How to create new NSDate object from [myUIDatePicker date] ?
I initiated an NSDate with [NSDate date]; and I want to check whether or
For example I have NSDate *curDate = [NSDate date]; and its value is 9:13
I have a problem with this code: NSDate *today = [[NSDate alloc] init]; if
i have an NSDate object from an old date which i am getting from
I'm trying to get NSDate from UIDatePicker , but it constantly returns me a

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.