We've updated the ServiceNow Community Code of Conduct, adding guidelines around AI usage, professionalism, and content violations. Read more

Help with Date field

User485076
Tera Contributor

Hello, 

I have a date field on a catalog form. I basically need to get the value of the date in this field and today's date and then do some calculations. However, when I log the dates, I'm getting it in the wrong format and time zone. Screenshot attached, I need the scheduled date to show in the same format as todays date.

 

 var selectedDate = new Date(newValue);
  console.log("selected date is: ", selectedDate);
  var today = new Date();
  console.log("today date: ", today);
 
User485076_0-1704714771085.png

 

12 REPLIES 12

@User485076 you need to use above code in server side script not in catalog client script.

vermaamit16
Kilo Patron

Hi @User485076 

 

Please let me know where you are running this script into ? Like in a catalog client script or a Script Include or a Fix Script ?

 

Thanks & Regards

Amit Verma

Thanks and Regards
Amit Verma

It's a catalog client script. GlideDate is server side 

Yes. It is server side script. you need to add in script include and call script include from catalog client script

vermaamit16
Kilo Patron

Hi @User485076 

 

If you want to handle this completely in your client script only, use below logic :

 

var today_date = new Date();
var day = today_date.getDate();
var month = today_date.getMonth();
month = month + 1;
var year = today_date.getFullYear();
var today_date_str = day + "-" + month + "-" + year;

 

Thanks & Regards

Amit Verma

Thanks and Regards
Amit Verma