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 / get local date time in...
Power Pages
Unanswered

get local date time in liquid

(0) ShareShare
ReportReport
Posted on by 66

hi,

 

How can i get local date time in liquid. When i am using below code, it is returning me utc date time.

 

{% assign currentDateTime= now %}
 
i want current date of user and set value in currentDateTime in liquid.

Thanks
Categories:
I have the same question (0)
  • timl Profile Picture
    36,383 Super User 2025 Season 2 on at

    Hi @jeffgreenrc 

    From what I see, there doesn't seem an easy way to do this.

    In the post here, Nicholas Hayduk recommends the JavaScript library moment.js.

    https://community.dynamics.com/crm/f/microsoft-dynamics-crm-forum/268880/crm-portals-date-issue---liquid-rendering-date-in-utc?pifragment-97030=1

    That is, you could use liquid to retrieve todays utc date/time (or whatever date/time you want to format), and use moment.js to convert it to the local value, clientside.

    https://himbap.com/blog/?p=3493

    Is that something that could work for you?

  • Fubar Profile Picture
    8,338 Super User 2025 Season 2 on at

    Also, if you provide some indication of why you need it in Liquid etc it may help people to provide possible workarounds etc.

  • oliver.rodrigues Profile Picture
    9,368 Most Valuable Professional on at

    Tell us a bit more about your scenario. You might be able to use entity form metadata if you just need to set current date to a field. You might be able to achieve via plugins/workflows, etc. 

  • jeffgreenrc Profile Picture
    66 on at

    Thank you for your responses.


    I am using currentDateTime in fetchxml to load records based on datetime filter.

     

    In my current fetchxml entity datetime=currentDateTime.

     

    Thanks

     

  • oliver.rodrigues Profile Picture
    9,368 Most Valuable Professional on at

    Hi, you can create a variable in liquid and assign the current date, and then use that in your fetch:

    {% assign currentDate = now | date: "yyyyMMddHHmmss" %}
    {% assign conditionCache = ' <condition attribute="new_name" operator="ne" value="' | append: currentDate | append: '" />' %}

    You can also define the format using the | date filter

    This example I am creating a condition and then using in a fetch, as per below: 

    {% fetchxml myFetch %}
     <fetch>
     <entity name="new_entityname">
     <filter type="and">
     {{ conditionCache }}
     </filter>
     </entity>
     </fetch>
    {% endfetchxml %}

     

  • jeffgreenrc Profile Picture
    66 on at

    Thank you for your response.

     

    I have done how you shown above. The issue with above code is, "now" returns value in utc time. Whereas, I want to get current local datetime.

     

    I want to basically set currentDateTime variable in liquid to users local current datetime.


    Thanks

  • oliver.rodrigues Profile Picture
    9,368 Most Valuable Professional on at

    Thanks, I didn't understand your issue was timezone.

    Take a look at this thread: Web Template : Display date in specific timezone - Microsoft Dynamics CRM Forum Community Forum

    it's a bit old but still valid, basically there is another filter you can use via Liquid, or you can also use the moment.js library

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