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

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Pages / Set date field to toda...
Power Pages
Answered

Set date field to todays date using jquery

(0) ShareShare
ReportReport
Posted on by 10

Hi, 

I have a date field(cr2d2_approvedon) on power portal form , I tried setting its value to todays date using $('#cr2d2_approvedon_datepicker_description') .val(new Date().toLocaleDateString()) and

$('#cr2d2_approvedon') .val(new Date().toLocaleDateString())

,but when I submit the form , the cr2d2_approvedon column is showing empty in dataverse, Can anyone please help me with this.

Categories:
I have the same question (0)
  • Saud Ali Profile Picture
    812 Super User 2024 Season 1 on at

    Hi @PPBeginner ,

     

    Are you setting this Date on creation of record? If yes, then instead of using JavaScript you should use form metadata to set values at the time of creation. 

     

    Please share if there are any concerns.

     

    Thanks,

    Saud

     

    If you like this post, give a Thumbs up. Where it solved your request, Mark it as a Solution to enable other users find it.

  • Verified answer
    Fubar Profile Picture
    8,487 Super User 2026 Season 1 on at

    Date is a 'complex' field as it also accommodates the datepicker, you will probably find setting a default date in the DatePicker control will give you what you want - the following JavaScript snippet should give you enough details to work out how to set to Today (note: the snippet would be placed inside a JQuery document.ready):

     

     

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

     

     

     

    This link also has some other datepicker operations https://powerusers.microsoft.com/t5/General-Discussions/Date-Picker-modified-through-javascript-fails-required-field/m-p/1938281/highlight/true#M1917

     

    Edit: user form Metadata records if wanting to capture a date when a record was updated or created (where the out of the box created on or modified on is not sufficient).

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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Users!

Kudos to our 2025 Community Spotlight Honorees

Congratulations to our 2025 community superstars!

Congratulations to the March Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Pages

#1
DP_Prabh Profile Picture

DP_Prabh 51

#2
rezarizvii Profile Picture

rezarizvii 35

#3
oliver.rodrigues Profile Picture

oliver.rodrigues 33 Most Valuable Professional

Last 30 days Overall leaderboard