1

I have used this to get the server date,

$yd = getdate();

echo $yd['year'];
echo $yd['mon'];
echo $yd['mday'];

...but how do I add something to it. For example, I want to know what date it will be in 7 days.

Thanks!

2 Answers 2

4
echo date("Y-m-d",strtotime("+7 days"));
Sign up to request clarification or add additional context in comments.

3 Comments

THANKS! It works. And another quick question, can I also compare them? such as if ( date("Y-m-d") > 21-12-2010 ) {} ? to know if this date has already passed or not.
You can compare them, but make sure the format is the same - unlike in your example. Do it like date("Y-m-d") > "2010-12-14".
I usually force them both to be unix timestamp so my comparison would be strtotime(date("Y-m-d")) > strtotime("2010-12-24")
1

Use strtotime()

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.