How to set Catalog item variable date/time to display short date/time?

Nicholas Hromya
Mega Guru

I want the Catalog Item variable of date/time (could be single line text) in the service portal to NOT show seconds or  milliseconds.

 

I understand this can be set on the display for user preferences, however, two things, it is already set to not show seconds and I have found this is not applying it to the catalog item within the service portal and not in the notifications when it displays this variable.

 

I was looking at something like the below, but I don't see how I can apply this to the variable type date/time.

 

var gd = new GlideDate();

var displayValue = gd.getDisplayValue();

gs.info('Display Value: ' + displayValue); // Output: Display Value: 11-13-2023

 

or can I add this to my notification?

=FormatDateTime(variablename, DateFormat.ShortDate)

 

Thanks in advance.

Nick

7 REPLIES 7

swathisarang98
Giga Sage
Giga Sage

Hi @Nicholas Hromya ,

 

Instead  of coding you can change the catalog Item Variable field "type" to "Date" which will give you date in yyyy-mm-dd format without any time values,

 

swathisarang98_1-1709334491109.png

 

 

swathisarang98_0-1709334448757.png

 

Please mark this comment as Correct Answer/Helpful if it helped you.

Regards,

Swathi Sarang

 

Hello @swathisarang98 

I still want the hour and minutes, just not the seconds. 

So, yah, the 

var gd = new GlideDate()

is not enough...

 

@Nicholas Hromya , You can create a onload script to set the value of that field to show date and time as below, making sec as 00

swathisarang98_0-1709336409345.png

 

 

function onLoad() {
    var value = g_form.getValue('date');
    var dateTime = value.split(' ')[0];
    var sec = value.split(' ')[1].split(':');
    var result = dateTime + ' ' + sec[0] + ':' + sec[1] + ':' + '00';
    g_form.setValue('date', result);

}

 

 But it will not work for form view in portal so in client script you need remove check box likeApplies on a Catalog Item view

swathisarang98_1-1709336620830.png

 

Please mark this comment as Correct Answer/Helpful if it helped you.

Regards,

Swathi Sarang

 

@Nicholas Hromya  there is one more way to make sure all Date/time field gives hours and minutes but it might be global change which can effect other configuration

 

System properties -> system - Time format

swathisarang98_0-1709337180662.png

 

Please mark this comment as Correct Answer/Helpful if it helped you.

Regards,

Swathi Sarang