How to get Date in proper format in symfony2 writing own console Command
$plantype = $allDbName->getPlanType();
$planEndOn = $allDbName->getNextPaymentDate();
$p = $planEndOn->format('H:i:s \O\n Y-m-d');
$currentDate = new \DateTime();
$date = date_modify($p, '-5 day');
$output->writeln($date);
getting error in console
DateTime::format()
returns a string, so $p
is a string, not a DateTime.
You should do something like this instead
$planEndOn = $allDbName->getNextPaymentDate();
$planEndOn->modify('-5 days');
$output->writeln($planEndOn->format('H:i:s \O\n Y-m-d'));
The errormessage is clear,
date_modify($p, '-5 day');
expects $p
to be a dateTime Object
but at this point its a string because you already formatted as string with ->format()
so change the order of your script :
$plantype = $allDbName->getPlanType();
$planEndOn = $allDbName->getNextPaymentDate();
$p = date_modify($planEndOn, '-5 day');
$date = $p->format('H:i:s \O\n Y-m-d');
$output->writeln($date);
I got solution
$planEndOn = $allDbName->getNextPaymentDate() ? $allDbName->getNextPaymentDate()->format('Y-m-d') : 0;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With