• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Getting the last date of the month?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Getting the last date of the month?


  • Subject: Re: Getting the last date of the month?
  • From: Deborah Goldsmith <email@hidden>
  • Date: Fri, 23 Mar 2007 15:21:17 -0700

I missed the original post, but I think [NSCalendar rangeOfUnit:inUnit:forDate:] might be an easier way to do this.

Deborah Goldsmith
Internationalization, Unicode liaison
Apple Inc.
email@hidden

On Mar 20, 2007, at 11:01 AM, Jim Thomason wrote:

If you are starting with the first day of the month, as your
"firstDayOfMonth" variable name suggests, then you ought to be able
to add one month and subtract one day to get the last day of the
month.

This can be genericized even further. Apparently, NSCalendarDate treats the "0th" of the month as the last day of the previous month. So if you increment by 1 month and decrement by your current day of month, it also works.

NSCalendarDate* lastOfThisMonth = [currentDate dateByAddingYears:0
months:1 days:- [currentDate dayOfMonth] hours:0 minutes:0 seconds:0];

-Jim.....
_______________________________________________

Cocoa-dev mailing list (email@hidden)

Do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden

_______________________________________________

Cocoa-dev mailing list (email@hidden)

Do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


  • Follow-Ups:
    • Re: Getting the last date of the month?
      • From: Nick Zitzmann <email@hidden>
References: 
 >Getting the last date of the month? (From: Nick Zitzmann <email@hidden>)
 >Re: Getting the last date of the month? (From: Greg Titus <email@hidden>)
 >Re: Getting the last date of the month? (From: "Jim Thomason" <email@hidden>)

  • Prev by Date: Core Data
  • Next by Date: Re: Is there a way to re-compile a framework for Intel Mac?
  • Previous by thread: Re: Getting the last date of the month?
  • Next by thread: Re: Getting the last date of the month?
  • Index(es):
    • Date
    • Thread