• 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: "Jim Thomason" <email@hidden>
  • Date: Tue, 20 Mar 2007 13:01:18 -0500

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


  • Follow-Ups:
    • Re: Getting the last date of the month?
      • From: Deborah Goldsmith <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>)

  • Prev by Date: Re: Getting the last date of the month?
  • Next by Date: Re: Detecting when menubar is visible
  • 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