Is there a PHP function I can use to do something like the following:
- Get the date 6 months ago (e.g. now – 6 months)?
- Get the date 2 years from now (e.g. now + 2 years)?
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.
Yes, there is: strtotime():
strtotime("-6 months");strtotime("+2 years");These will return Unix timestamps. So you might want to put the result into
date()orlocaltime()orgmtime().Please do not try to subtract 6 months or add 2 years of seconds to
time(). This does not take into account things like daylight saving or leap seconds and still gives you a value in seconds which is unlikely to be the precision you need. Let the library functions do it.