How to get the date without Time from NSDate?

Ghass.64 picture Ghass.64 · Jun 20, 2012 · Viewed 17.7k times · Source

I want to get the date from NSDate and do not need time. Example:

NSDate* today = [NSDate date];  // want to give 20-06-2012 only

I want to get the date for today without showing the time and use it in NSDate variable or string variable.

Answer

jody picture jody · Jul 13, 2013

In case someone else looks for this. I used the following:

NSDateComponents *components = [[NSCalendar currentCalendar] 
             components:NSYearCalendarUnit|NSMonthCalendarUnit|NSDayCalendarUnit 
              fromDate:[NSDate date]];
NSDate *startDate = [[NSCalendar currentCalendar] 
             dateFromComponents:components];