How can I get the last day of the current month as an NSDate
?
=EOMONTH(A2, -1) - returns the last day of the month, one month before the date in cell A2. Instead of a cell reference, you can hardcode a date in your EOMONTH formula.
DateTime createDate = new DateTime(year, month, 1). AddMonths(1). AddDays(-1);
NSDate *curDate = [NSDate date]; NSCalendar* calendar = [NSCalendar currentCalendar]; NSDateComponents* comps = [calendar components:NSYearCalendarUnit|NSMonthCalendarUnit|NSWeekCalendarUnit|NSWeekdayCalendarUnit fromDate:curDate]; // Get necessary date components // set last of month [comps setMonth:[comps month]+1]; [comps setDay:0]; NSDate *tDateMonth = [calendar dateFromComponents:comps]; NSLog(@"%@", tDateMonth);
should also work.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With