I am new on dates with Symfony. I try to use the PHP website instructions in my Symfony 3.3 Controller, and I can't get an answer. For example, I want to add 10 days to my date. In the web: http://php.net/manual/en/datetime.add.php Php sugests this way:
<?php
$date = new DateTime('2000-01-01');
$date->add(new DateInterval('P10D'));
echo $date->format('Y-m-d') . "\n";
?>
I used the first two lines in my Symfony 3.3 Controller:
namespace Food\FruitBundle\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\Response;
class DefaultController extends Controller
{
public function addAction()
{
$date = new DateTime('2000-01-01');
$date->add(new DateInterval('P10D'));
return new Response($date);
}
I got this mistake:
Attempted to load class "DateTime" from namespace "Food\FruitBundle\Controller".
Did you forget a "use" statement for "Symfony\Component\Validator\Constraints\DateTime"?
Then I add the use instruction:
Now it shows this mistake:
"No default option is configured for constraint Symfony\Component\Validator\Constraints\DateTime"
How can I use a DateTime instruction, such as add? Thanks!