Created
November 15, 2013 09:58
-
-
Save sag333ar/7481939 to your computer and use it in GitHub Desktop.
Current date - 2 months period = the date which you get after executing following function
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- (NSDate*)twoMonthspastDate { | |
NSCalendar *cal = [NSCalendar currentCalendar]; | |
NSDate *now = [NSDate date]; | |
NSDateComponents *comp = [cal components:NSDayCalendarUnit | NSMonthCalendarUnit | NSYearCalendarUnit fromDate:now]; | |
comp.timeZone=[NSTimeZone defaultTimeZone]; | |
comp.month = comp.month-2; | |
comp.year = comp.year; | |
comp.day = 1; | |
[comp setHour:0]; | |
[comp setMinute:0]; | |
[comp setSecond:0]; | |
NSDate *lastMonthFirstDate = [cal dateFromComponents:comp]; | |
return lastMonthFirstDate; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment