In Craft 2 I've used createFromString() as following:

DateTime::createFromString($pubDate, craft()->timezone)

But if I use this function in craft cms 3 then I'm getting the following error:

Call to undefined method DateTime::createFromString()

Is there any alternative way to use the createFromString() in Craft 3?

1 Answer 1


You're looking for the toDateTime() method in the DateTimeHelper class:

DateTimeHelper::toDateTime($pubDate, true);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.