<p>You're looking for the <a href="https://docs.craftcms.com/api/v3/craft-helpers-datetimehelper.html#method-todatetime" rel="nofollow noreferrer"><code>toDateTime()</code> method</a> in the <code>DateTimeHelper</code> class:</p>

<pre><code>DateTimeHelper::toDateTime($pubDate, true);
</code></pre>

CC BY-SA 4.0
2020-06-10T16:40:07.483Z
2020-06-10T16:40:07.483Z
Jalen Davenport
<p>In Craft 2 I've used <a href="https://docs.craftcms.com/api/v2/craft-datetime.html#method-createfromstring" rel="nofollow noreferrer">createFromString()</a> as following:</p>

<pre><code>DateTime::createFromString($pubDate, craft()-&gt;timezone)
</code></pre>

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

<pre><code>Call to undefined method DateTime::createFromString()
</code></pre>

<p>Is there any alternative way to use the createFromString() in Craft 3?</p>

<craft3><datetime>
How to use createFromString() in Craft 3
# How to use createFromString() in Craft 3

(Asked by: username_0 on 2020-06-10)

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?

**Tags:** craft3, datetime

---

## 1 answers

### Answer by username_1 on 2020-06-10. Score: 2 | Accepted answer

You're looking for the toDateTime() method in the DateTimeHelper class:
DateTimeHelper::toDateTime($pubDate, true);


---

