Skip to content
Advertisement

Message: DateTime::__construct(): Failed to parse time string (21/12/2020) at position 0 (2): Unexpected character

$start = new DateTime(21/12/2020);

while executing this statement, it gives following error: Type: Exception

Message: DateTime::__construct(): Failed to parse time string (21/12/2020) at position 0 (2): Unexpected character

What could be the reason for this error and what is the solution for it?

Advertisement

Answer

Try to replace slashes with dots or slash slashed (like 21/12/2020). Better don’t use slashes in that context.

User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement