Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

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

Amit Verma
Kilo Patron
Kilo Patron

Hi @User485076 

 

Please check if below post is helpful :

 

https://www.servicenow.com/community/toronto-snug/in-client-script-how-can-i-compare-2-dates-with-ti...

 

Thanks & Regards

Amit Verma


Please mark this response as correct and helpful if it assisted you with your question.

Hi Amit, I thought about using getDisplayValue. This would correctly log the scheduled date as DD/MM/YYYY. However, I'm also getting todays date, this isn't a field on the form. How can I alter the format here to be the same as the field on the form:

var today = new Date();

 

Thanks

Akshata T
Tera Guru

@User485076 You will get today's date and you can format as per your requirement using below code.

var todayDate= new GlideDate();
todayDate.getByFormat("dd-mm-yyyy");

Hi Akshata, 

 

Getting error: ReferenceError: GlideDate is not defined