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

Prince Arora
Tera Sage
Tera Sage

@asher14 ,

 

Tried & Tested in client script

 

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;
alert(today)

 

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

is alert a pop up? I want the value to display on the 'u_arrival_date' field value on the service portal widget

@asher14 ,


If you are working in native view client script, please use

g_form.setValue('Backend_Name_of_field' , DATE);

 

Please share the snippet where you are writing this script if it is not working!

 

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

 

g_form.setValue('Backend_Name_of_field' , DATE);

is date identifying as whatever the current date is?