How can I get the current date – 3 months? I need it for a database query to get all files in the last 3 months.
I know the operation “dateByAddingTimeInterval” but I would have to subtract the 3 months instead.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Depending how you define 3 month. If you mean the same day 3 months ago you could do sth like this:
of course you could also change the month without having to create the extra date, but I thought thi is clearer and more flexible, in case you like to debug and possible change days as well, in case you define 3 months ago by -n days depending in which month we are. eg – (30+31+30), or -(31+30+31) or having to account for februray 28 days.
Again, all depends how you define 3 months ago… but this should lead you to the solution