web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Pages / Liquid error: Object o...
Power Pages
Unanswered

Liquid error: Object of type 'System.DateTime' cannot be converted to type 'System.String'.

(0) ShareShare
ReportReport
Posted on by 11

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>

var firstname="{{ user.firstname }}";
var lastname="{{ user.lastname }}";
var birthdate="{{ user.birthdate | string }}"; //"{{ user.birthdate }}";
</script>

 

firstname and lastname works fine.

Any help?

Categories:
I have the same question (0)
  • OOlashyn Profile Picture
    3,496 Most Valuable Professional on at

    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 }}"; 
  • Siddique mahsud Profile Picture
    11 on at

    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: 

    siddiqueMahsud_7-1631255072873.png

     


    Output:

    siddiqueMahsud_6-1631255059524.png

     


    Also, I used like below:

     

    var birthdate="{{ user.birthdate }}"; 
    alert(birthdate);

     

    and got below in alert:​

    siddiqueMahsud_3-1631254681115.png

     

     

     

  • Eduardo_Garcia Profile Picture
    5 on at

    I'm getting the same issue out of nowhere. Any ideas?

  • H V Profile Picture
    1,510 on at

    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!

  • Eduardo_Garcia Profile Picture
    5 on at

    Thanks, but it doesn't work. It seems like the latest portal update broke parsing of boolean and datetime for the user object.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Forum hierarchy changes are complete!

In our never-ending quest to improve we are simplifying the forum hierarchy…

Ajay Kumar Gannamaneni – Community Spotlight

We are honored to recognize Ajay Kumar Gannamaneni as our Community Spotlight for December…

Leaderboard > Power Pages

#1
Jerry-IN Profile Picture

Jerry-IN 71

#2
Fubar Profile Picture

Fubar 62 Super User 2025 Season 2

#3
sannavajjala87 Profile Picture

sannavajjala87 31

Last 30 days Overall leaderboard