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.

Difference difference in script include

Tomi Corigliano
Kilo Sage

Hi,

I have some unexpected behavior with dates. It's probably due to the time zone.

 

checkIfDateIsCHforBRUandLUX: function(){

		var inputDate = this.getParameter('sysparm_date');
		gs.log('DWPCatalogClientUtils | checkIfDateIsCH | inputDate = ' + inputDate);
		var user = this.getParameter('sysparm_requested_for');
		var date = new GlideDate();
		gs.log('DWPCatalogClientUtils | checkIfDateIsCH | Today = ' + date);
		date.setDisplayValue(inputDate,'dd/MM/yyyy');

		gs.log('DWPCatalogClientUtils | checkIfDateIsCH | New date = ' + date);

},

 

The output = 

DWPCatalogClientUtils | checkIfDateIsCH | inputDate = 01/05/2024

DWPCatalogClientUtils | checkIfDateIsCH | New date = 2024-04-30

DWPCatalogClientUtils | checkIfDateIsCH | Today = 2024-03-18

 

Why is there a difference of 1 day between 'inputDate' and 'New date'? How can I fix this?

2 REPLIES 2

Harish KM
Kilo Patron
Kilo Patron

Hi @Tomi Corigliano the below will give you in user's time zone

var date = new GlideDate();;
gs.info(date.getDisplayValue());
also I see your setting date in 'dd/MM/yyyy' (users can have different format in their instance in that case it will fail)
before setting you need to check user's date format
here is the example
Regards
Harish

Krushna R Birla
Kilo Sage

Hi @Tomi Corigliano 

 

Its working as expected for me. Please find below snapshot, How I have verified in BG Script

 

krishbirla07_1-1710755841304.png

I would suggest you to please check users date format and set it as per below snapshot. Profile setting >> Preferences >> Language and region

 

krishbirla07_0-1710755683057.png

 

If this solution resolves your query, kindly mark it as the accepted solution and give it a thumbs up.

 

Feel free to connect with me on LinkedIn.

 

Best Regards,

Krushna Birla

Senior Software Engineer

Globant, Pune