Common Date operations in Objective-C

In this post, I’m going to provide you code snips for common date operations like yesterday, last month, last week etc. Just keep scrolling through code snips & I hope you would get what you need.

1. LastWeek: Get date of last week

2. Yesterday: Returns date of yesterday.

3. FirstDateForLastMonth: Get the First date of previous month.

4. Remove24HoursToDate: Current date – 24 hours = Today 5 PM – 24 hours = Yesterdays 5 PM

5. Add24HoursToDate: Add 23:59:59 hours to – (assume today is 30-Jul-2013) example range yesterday = 29-Jul-2013 12:00:00 AM + “to” + 30-Jul-2013 23:59:59 PM

6. CurrentDateMidnightTime: Get current Date mid-night time = 15-Feb-2013 00:00:00 So, You will get date with time 00:00:00 always.

7. TwoMonthspastDate: Current date – 2 months period = the date which you get after executing following function

8. DateTimeStampUnixFormat: Get current date-time-stamp in UNIX format

Leave a Reply

Your email address will not be published. Required fields are marked *