How to get today's date in MM-DD-YYYY format without time in widget's client controller?

asher14
Tera Contributor

I have a 'arrival date' that I would like to repopulate the date to the current day. I would place the code in my init function so when the page loads the date is already applied. How can I achieve this? 

1 ACCEPTED SOLUTION

@asher14 ,

 

var today = new Date();
var dd = String(today.getDate()).padStart(2, '0');
var mm = String(today.getMonth() + 1).padStart(2, '0'); 
var yyyy = today.getFullYear();

today = mm + '-' + dd + '-' + yyyy;

g_form.setValue('Backend_Name_of_field' , today );
//alert(today)

 

If my answer solved your issue, please mark my answer as Correct & 👍Helpful based on the Impact.

 

View solution in original post

5 REPLIES 5

@asher14 ,

 

var today = new Date();
var dd = String(today.getDate()).padStart(2, '0');
var mm = String(today.getMonth() + 1).padStart(2, '0'); 
var yyyy = today.getFullYear();

today = mm + '-' + dd + '-' + yyyy;

g_form.setValue('Backend_Name_of_field' , today );
//alert(today)

 

If my answer solved your issue, please mark my answer as Correct & 👍Helpful based on the Impact.