I'm trying to get birthDate (and other date fields) of the portal user(contact) in liquid in a content snippet, it give me the error "Liquid error: Object of type 'System.DateTime' cannot be converted to type 'System.String'."
<script>
firstname and lastname works fine.
Any help?
Hi @siddiqueMahsud,
If you would like to convert datetime to a specific format check this official doc regarding available datetime filters.
var date = "{{ now | date: 'MMM dd, yyyy' }}";
// output Sep 09, 2021
If you just want to print that value to use as a string you don't need any additional filter and this code will work just fine:
// this will be a string
var birthdate="{{ user.birthdate }}";
thank you OOlashyn for your response, seems like there is some issue with my portal, as I'm used the same as you mentioned but not working.
I just simply need the birthdate, no matter what is the format.
My sample code:
Output:
Also, I used like below:
var birthdate="{{ user.birthdate }}";
alert(birthdate);
and got below in alert:
I'm getting the same issue out of nowhere. Any ideas?
Hi @siddiqueMahsud & @Eduardo_Garcia
Can you please try below code:
{% assign birthDate = user.birthdate %}
{{ birthDate }}
--------------------------
If you like this post, give a Thumbs up. Where it solved your query, Mark as a Solution so it can help other people!
Thanks, but it doesn't work. It seems like the latest portal update broke parsing of boolean and datetime for the user object.
User | Count |
---|---|
3 | |
1 | |
1 | |
1 | |
1 |