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 / Set Date Field Via Jav...
Power Pages
Unanswered

Set Date Field Via Javascript

(0) ShareShare
ReportReport
Posted on by 37

Hi,

 

I'm trying to set a date field via java-script; however cannot seem to get the formatting it requires correct.

 

I have tried multiple different date formats e.g. 'dd/MM/yyyy' but cannot find the one it requires.

 

https://docs.microsoft.com/en-us/dotnet/standard/base-types/standard-date-and-time-format-strings

 

Date.PNG

 

 

$( document ).ready(function() {

// attempt 1
$("#xxx_yearofjoiningthesociety").val("{{ mem.c2memb_fromdate | date_to_iso8601 }}").addClass("readonly");

// attempt 2
$("#xxx_yearofjoiningthesociety").val("{{ mem.c2memb_fromdate | date:'d' }}").addClass("readonly");

// attempt 3
$("#xxx_yearofjoiningthesociety").val("{{ mem.c2memb_fromdate | date:'g' }}").addClass("readonly");

// attempt 4
$("#xxx_yearofjoiningthesociety").val("{{ mem.c2memb_fromdate | date:'dd/MM/yyyy' }}").addClass("readonly");

});

 


@OOlashynmentioned something similar in another thread but could not see the formatting

Thanks,

Categories:
I have the same question (0)
  • Verified answer
    Fubar Profile Picture
    8,338 Super User 2025 Season 2 on at

    You are not accessing the date control correctly to set it, and the date control is probably expecting a JavaScript date object, (your Liquid code is just outputting text or a liquid date object).

     

    To default a date you would do something like the following (where you would replace the date text part "2021-01-01" with output from Liquid)

     

    // set a default date
    $("#your_fieldname") // input control
     .next() // the date picker container
     .data("DateTimePicker") // the date picker object
     .defaultDate(new Date("2020-01-01"));

     

     

    (you may still be able to use .val() but it would be expecting a javascript date object)

  • g.whammond Profile Picture
    37 on at

    @FubarYour a star. Thank you.

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