Unable to set display date format

bigbacon
Giga Guru

I am returning some dates from a script include to a form and they always come in as yyyy-mm-dd or whatever the base format is but I want the displayed value in the date picker box to show as MM/dd/yyyy and it doesn't seem to like me trying to use GlideDate functions in the Client UI script box and I am unsure why.

 

I also tried having my script include code format in a MM/dd/yyyy format and it was also not happy with me trying to do that.

 

If you select a date manually using the box its in MM/dd/yyyy.

1 REPLY 1

JenniferRah
Mega Sage

Dates are so much fun (sarcasm) in SN. 😁

 

You are correct. You cannot use GlideDate functions on the client side. Those are for server side code only. 

 

Assuming this is a Date only function and you want to set it to today's date, I have used this:

 

 

var today = new Date();
var formattedDate =  ('0' + (today.getMonth() + 1)).slice(-2) + '/' + ('0' + today.getDate()).slice(-2) + '/' + today.getFullYear();
g_form.setValue('myvar', formattedDate);

 

 

 

If you want to set it to a value you pulled from somewhere else, you can use the same code but enter the variable with your date in it like this: 

 

 

var today = new Date(mydate);
var formattedDate =  ('0' + (today.getMonth() + 1)).slice(-2) + '/' + ('0' + today.getDate()).slice(-2) + '/' + today.getFullYear();
g_form.setValue('myvar', formattedDate);