Answers.Body: <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>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-06-10T16:40:07.483Z
Answers.LastActivityDate: 2020-06-10T16:40:07.483Z
Answers.UserDisplayName: Jalen Davenport
Body: <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>
  
Tags: <craft3><datetime>
Title: How to use createFromString() in Craft 3
ThreadText: # How to use createFromString() in Craft 3
  
  (Asked by: username_0 on 2020-06-10)
  
  In Craft 2 I've used [createFromString()](https://docs.craftcms.com/api/v2/craft-datetime.html#method-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](https://docs.craftcms.com/api/v3/craft-helpers-datetimehelper.html#method-todatetime) in the `DateTimeHelper` class:
  
  ```
  DateTimeHelper::toDateTime($pubDate, true);
  
  ```
  
  
  ---
  
  