using the script to get the time value

chandanpatra
Tera Contributor

Hi All,

I am getting the date and time value from the script var ab= 2024-12-24 05:48:45; but in the i want only the 05:48 time only and stored in the one of the variable , Can anyone suggest how to get it .

 

Thanks ,

Chandan

 

 

 

1 ACCEPTED SOLUTION

Harish Bainsla
Kilo Patron

Hi @chandanpatra i check in background script my code is working fine use below script and do modification as per you need

var gdt = new GlideDateTime("2024-12-24 05:48:45");
var timeSection = gdt.toString().split(' ')[1]; //Gets the Time
year = gdt.getYearUTC();
month = gdt.getMonthUTC();
day = gdt.getDayOfMonthUTC();
hour = timeSection.split(':')[0];
minute = timeSection.split(':')[1];
gs.print(hour +':'+minute );
 
HarishBainsla_0-1735028992626.png

 

HarishBainsla_1-1735029003656.png

 

If my answer helps you mark helpful and accept solution

View solution in original post

3 REPLIES 3

Harish Bainsla
Kilo Patron

Hi @chandanpatra i check in background script my code is working fine use below script and do modification as per you need

var gdt = new GlideDateTime("2024-12-24 05:48:45");
var timeSection = gdt.toString().split(' ')[1]; //Gets the Time
year = gdt.getYearUTC();
month = gdt.getMonthUTC();
day = gdt.getDayOfMonthUTC();
hour = timeSection.split(':')[0];
minute = timeSection.split(':')[1];
gs.print(hour +':'+minute );
 
HarishBainsla_0-1735028992626.png

 

HarishBainsla_1-1735029003656.png

 

If my answer helps you mark helpful and accept solution

Ankur Bawiskar
Tera Patron

@chandanpatra 

you are doing this in server side or client side?

you will have to use string manipulation and get only the hours and minutes

var ab= 2024-12-24 05:48:45;
var time = ab.split(' ')[1];
var hourMin = time.split(':')[0] + ':' + time.split(':')[1];

If my response helped please mark it correct and close the thread so that it benefits future readers.

@chandanpatra 

as per new community feature you can mark multiple responses as correct.

If my response helped please mark it correct as well so that it benefits future readers.