# Convert basic date string to dateobject (no time in string)

**URL:** <https://community.hubspot.com/t/convert-basic-date-string-to-dateobject-no-time-in-string/16742>\
**Category:** CMS Development\
**Created:** [October 15, 2019, 9:49am UTC](https://community.hubspot.com/t/convert-basic-date-string-to-dateobject-no-time-in-string/16742 "2019-10-15T09:49:01Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![benji\_thecroc](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/benji_thecroc/32/31851_2.png) [@benji\_thecroc](https://community.hubspot.com/u/benji_thecroc)\
**Post date:** [October 15, 2019, 9:49am UTC](https://community.hubspot.com/t/convert-basic-date-string-to-dateobject-no-time-in-string/16742/1 "2019-10-15T09:49:01Z")

</div>

Hi,

I’m have an issue. We have event posts that have basic single line text field. In that the content publisher is putting in the date like so (d-m-Y e.g. 03-09-2019).

I’ve tried to use strtotime to convert this string into a dateobject which I can then use to convert into reading somethign like 3 Sept 19.

I think the issue is strtotime doesn’t like that there’s not time e.g.

```auto
{% set edate = post.widgets.event_date.body.value|strtotime('d/m/Y') %}

<p>{{ edate|datetimeformat('%e') }}</p>

```

---

<div class="post-metadata">

**Author:** ![Kevin-C](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/kevin-c/32/34570_2.png) [@Kevin-C](https://community.hubspot.com/u/Kevin-C)\
**Post date:** [October 22, 2019, 5:59pm UTC](https://community.hubspot.com/t/convert-basic-date-string-to-dateobject-no-time-in-string/16742/2 "2019-10-22T17:59:26Z")

</div>

Hey [@benji\_thecroc](https://community.hubspot.com/t5/user/viewprofilepage/user-id/54367)

As with most of my post(lol)…I’m no expert, but I gave it a shot!

It looks like your “strtotime” arguments are formated incorrectly.

As per the docs your year should be labeled as “yyyy”, month as “MM”, and day as “dd”. All separated by “-”. The user’s input should be formated in this way as well.

`|strtotime("yyyy-MM-dd'T'HH:mm:ssZ")|unixtimestamp`

It is also missing the time stamp which unfortunately is require. You could append a generic timestamp dynamically if it is not needed on your end.

Maybe something like this?

```auto
{# adding a generic timestamp #}
{% set inputDate = post.widgets.event_date.body.value~"T00:00:00+0000" %} 

{# declare edate #}
{% set edate = inputDate|strtotime("yyyy-MM-dd'T'HH:mm:ssZ")|unixtimestamp %} 

{# print value #}
<p>{{ edate|datetimeformat('%e') }}</p>

```

I hope this helps!
