Always display Date/Time variable in format YYYY/MM/DD HH:MM:SS

Basim Zaidi
Mega Expert

Hi Community,

I would like a specific Date/Time variable that I have on a Catalog Item to always display in the format [YYYY-MM-DD HH:MM:SS] on both the Service Catalog view and Service Portal, even if the logged in user has their date format profile preference set to something different and/or even if the system date format (glide.sys.date_format) is set to something different (for example, DD/MM/YYYY).

Any advice would be greatly appreciated.

Thanks,

Bas

4 REPLIES 4

Munender Singh
Mega Sage

Hi,

YYYY-MM-DD HH:MM:SS is the default format of servicenow and I don't think you would have any problem in setting this up.If any issues you can post here.

Regards,

Munender

Thanks for your response Munender.  The question I'm asking is can it be displayed in format YYYY-MM-DD even if the system properties or user preference is set to something different, e.g. DD/MM/YYYY?

Basim Zaidi
Mega Expert

The reason for my question is "date validation".  I want to alert the user when the variable (clz_expiry_date) is in the past.  Because ServiceNow stores the system date by default to YYYY-MM-DD, my Client Script/Script Include determines that 01/03/2019 (1 March 2019) is in the past.

Script Include (Client callable):

var DANNewDate = Class.create();
DANNewDate.prototype = Object.extendsObject(AbstractAjaxProcessor, {
	
	getDateDiff: function() {
		
		var cur = gs.nowDateTime();
		var t=this.getParameter('sysparm_dt1');
		
		if(t>cur || t=="") {
			return 0;
		}
		if(t<cur)
		{
			return 1;
		}
	}
});

 

Client Script:

function onChange(control, oldValue, newValue, isLoading) {
	var dt1=g_form.getValue('clz_expiry_date');
	var aj = new GlideAjax('DANNewDate');  
	aj.addParam('sysparm_name','getDateDiff');  
	aj.addParam('sysparm_dt1', dt1);  
	aj.getXML(diff);  
	
	function diff(response) {
		
		var ans=response.responseXML.documentElement.getAttribute("answer");
		
		if(ans==0) {
			return true;
		}
		else if(ans>0)
		{
			alert('Expiry date cannot be in the past');
			g_form.setValue('clz_expiry_date',"");
		}
	}
}

My thinking is that setting this specific variable to always display in YYYY-MM-DD format will get around this issue?

Hi,

Hope this would help you out in resolving issue,

getDisplayValue() shows the date/time in the users' preferred display format.   So you could use that on both dates to have same format and it would be of great hep in comparing.

 

Regards.

Munender