1

In my project i have to get the expiry date of a package from the 'date of purchasing' the package and the 'validity in days' of the package.I got a code from the php.net as follows

<?php
$date = new DateTime('2000-01-01');
$date->add(new DateInterval('P10D'));
echo $date->format('Y-m-d') . "\n";
?>

Now suppose the date of purchase is like 2013-01-17 and the validity in days is 180 Now if i use the php.net example as follows

<?php
$date = new DateTime('2013-01-17');
$date->add(new DateInterval('P180D'));
echo $date->format('Y-m-d') . "\n";
?>

Will i get the output as 2013-04-17? I need the output like

yyyy-mm-dd

I cant run the program in my personal computer but i have to carry on the codding of the project so i'm here.

1 Answer 1

4
<?php
 $date = new DateTime('2013-01-17');
 $date->add(new DateInterval('P180D'));
 echo $date->format('Y-m-d') . "\n";
?>

//output
//2013-07-16   and it is in yyyy-mm-dd format

working example http://codepad.viper-7.com/gAtT2D

and if you can't run the program in your PC, use online debugger shell.

Sign up to request clarification or add additional context in comments.

1 Comment

thanks fro codepad viper link...i was trying in codepad.org but there was a fatal error for my code

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.