CMS Development

TejasSingh
Member

How to convert date string (dd/MM/yy) to date object in HubL?

SOLVE

Hi,

 

I am trying to convert the string date which displays as dd/mm/yy to date object. There is a pick date property in hubspot that returns the date in dd/mm/yy. I want to use this to compare to another date object.

 

here is the code: contact.date_authorized gives out string 1/15/21

 

 

 {% if request_contact.is_logged_in %} 

      {% set autdate = contact.date_authorized|strtotime("yyyy-MM-dd'T'HH:mm:ssZ") %}

{% set after2021 = "2020-01-01T14:31:30+0530"|strtotime("yyyy-MM-dd'T'HH:mm:ssZ")|unixtimestamp }} %}

      {% if autdate > after2021 %}
      print xyz

{% endif %}

 

 

0 Upvotes
1 Accepted solution
Kevin-C
Solution
Recognized Expert | Partner
Recognized Expert | Partner

How to convert date string (dd/MM/yy) to date object in HubL?

SOLVE

Hey @TejasSingh 

 

Basically you've got to reformat that string so hubl can understand and translate it into a new date object.

 

 

{% set dateStr = '1/15/21' %}
		
{% set dateArr = dateStr|split("/", 1000) %}
		
{% set useDate = [
    (dateArr[2]|int + 2000),
    (dateArr[0]|length == 1 ? '0' + dateArr[0] : dateArr[0]),
    (dateArr[1]|length == 1 ? '0' + dateArr[1] : dateArr[1])
  ]
%}

{% set newDateObj = (useDate[0] + "-" + useDate[1] + "-" + useDate[2] + "T14:31:30+0530")|strtotime("yyyy-MM-dd'T'HH:mm:ssZ")  %}
		
		
{{ newDateObj }}

 

 

 

Kevin Cornett - Sr. Solutions Architect @ BridgeRev

View solution in original post

4 Replies 4
Jon_Sasala
Top Contributor | Diamond Partner
Top Contributor | Diamond Partner

How to convert date string (dd/MM/yy) to date object in HubL?

SOLVE

Thank you @Kevin-C  ❤️




Hypha HubSpot Development

Jon Sasala (He / Him)
President • Hypha HubSpot Development

Phone: 516-284-3333
Email: JSasala@HyphaDev.io
HyphaDev.io




LinkedIn Icon

Facebook Icon

Instagram Icon



P.S. The HubSpot Partner Directory accepts reviews. Please leave us a positive review and help us hit our goal of 200.



Kevin-C
Solution
Recognized Expert | Partner
Recognized Expert | Partner

How to convert date string (dd/MM/yy) to date object in HubL?

SOLVE

Hey @TejasSingh 

 

Basically you've got to reformat that string so hubl can understand and translate it into a new date object.

 

 

{% set dateStr = '1/15/21' %}
		
{% set dateArr = dateStr|split("/", 1000) %}
		
{% set useDate = [
    (dateArr[2]|int + 2000),
    (dateArr[0]|length == 1 ? '0' + dateArr[0] : dateArr[0]),
    (dateArr[1]|length == 1 ? '0' + dateArr[1] : dateArr[1])
  ]
%}

{% set newDateObj = (useDate[0] + "-" + useDate[1] + "-" + useDate[2] + "T14:31:30+0530")|strtotime("yyyy-MM-dd'T'HH:mm:ssZ")  %}
		
		
{{ newDateObj }}

 

 

 

Kevin Cornett - Sr. Solutions Architect @ BridgeRev
TejasSingh
Member

How to convert date string (dd/MM/yy) to date object in HubL?

SOLVE

Thank you very much Kevin, it worked like a charm! 🙂

 

Tejas

sharonlicari
Community Manager
Community Manager

How to convert date string (dd/MM/yy) to date object in HubL?

SOLVE

Hi @TejasSingh 

 

Thank you for sharing this information. 

 

I was investigating and I think this thread on the Community should be helpful for you. 

 

Thanks

Sharon


Did you know that the Community is available in other languages?
Join regional conversations by changing your language settings !