I am using the following line in a module
$firstNextMonth = date("Y-m-d H:i:s", strtotime(date('m', strtotime('+1 month')).'/01/'.date('Y').' 00:00:00'));
$d = DateTime::createFromFormat('Y-m-d H:i:s', $firstNextMonth);
$firstNextMonthTs = $d->getTimestamp();
But when i run the code in a staging server I get and error as magento it is
"Fatal Error: 'Uncaught Error: Class 'Magenest\\Stripe\\Model\\DateTime' not found in \/var\/www\/html\/magento2-theme-videx\/htdocs\/app\/code\/Magenest\/Stripe\/Model\/StripePaymentMethod.php:480\nStack trace:\n#0 \/var\/www\/html\/magento2-theme-videx\/htdocs\/app\/code\/Magenest\/Stripe\/Model\/StripePaymentMethod.php(829): Magenest\\Stripe\\Model\\StripePaymentMethod->authorize(Object(Magento\\Sales\\Model\\Order\\Payment\\Interceptor), '4.8')\n#1 \/var\/www\/html\/magento2-theme-videx\/htdocs\/vendor\/magento\/module-sales\/Model\/Order\/Payment\/Operations\/CaptureOperation.php(82): Magenest\\Stripe\\Model\\StripePaymentMethod->capture(Object(Magento\\Sales\\Model\\Order\\Payment\\Interceptor), '4.8')\n#2 \/var\/www\/html\/magento2-theme-videx\/htdocs\/vendor\/magento\/module-sales\/Model\/Order\/Payment\/Processor.php(85): Magento\\Sales\\Model\\Order\\Payment\\Operations\\CaptureOperation->capture(Object(Magento\\Sales\\Model\\Order\\Payment\\Interceptor), Object(Magento\\Sales\\Model\\Order\\Invoice))\n#3 \/var\/www\/html\/magento2-theme-videx\/htdocs\/vendor\/magento\/module-sales\/Model\/Order\/Payment.php(' in '\/var\/www\/html\/magento2-theme-videx\/htdocs\/app\/code\/Magenest\/Stripe\/Model\/StripePaymentMethod.php' on line 480"
Looks like magento or php it is trying to find the DateTime class instead of run the command
The php version is PHP 7.0.27 (cli) (built: Jan 25 2018 22:40:53) ( NTS )
any ideas ?
Add "use Magento\\Framework\\Stdlib\\DateTime;" line before class declaration than use code DateTime class as below:
$firstNextMonth = date("Y-m-d H:i:s", strtotime(date('m', strtotime('+1 month')).'/01/'.date('Y').' 00:00:00'));
$d = \DateTime::createFromFormat('Y-m-d H:i:s', $firstNextMonth);
$firstNextMonthTs = $d->getTimestamp();
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.