Have you ever faced the error stated below while working with the date field on the checkout page of the Magento 2 store?
DateTime::__construct(): Failed to parse time string at position 0 : Unexpected character
Never miss Magento tips, tricks, tutorials, and news.
I would be happy to help.
Solution: DateTime::__construct(): Failed to Parse Time String at Position 0 in Magento 2
Check out the solution here:
$var = ’01/01/2001′;
$date = str_replace(‘/’, ‘-‘, $var);
newDate = date(‘Y-m-d’, strtotime($date));
Something went wrong.
If you have any doubts regarding this error, just mention them in the Comments section below.
For instance, I’ve used my custom date field in the checkout page and storing the date in another format instead of its default, it results in the error that states Failed to parse time string at position 0 in Magento 2.
Use the below code in the file from which the date field is arriving.
Get Weekly Updates
If yes, then you are at the right place because we have the exact solution for you!
Feel free to share the solution with Magento Community via social media.
Thank you for subscribing.