Created
November 15, 2013 10:05
-
-
Save sag333ar/7482020 to your computer and use it in GitHub Desktop.
Get the First date of previous month.
This file contains hidden or 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 *)firstDateForLastMonth { | |
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-1; | |
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