How to formate datetime from this 2023-11-03 22:51:34 to this 20231103-225134.

Ajay Singh2
Tera Contributor

Can anyone explain how to use datetime in from this 2023-11-03 22:51:34 to this 20231103-225134.formate on onchange client script.

2 ACCEPTED SOLUTIONS

Hello @Ajay Singh2 

 

It seems you have already brought the datetime

 

Just use the below code :-

 

var gdt = g_user_date_time_format;
var dateTime = gdt.split(' ');
var date=dateTime[0].split('-');
var time=dateTime[1].split(':');
var res1= date[0]+date[1]+date[2];
var res2= time[0]+time[1]+time[2];
var res=res1 +'-' +res2;
alert(res);

View solution in original post

@Ajay Singh2Nah, if you would be using my code, you would have the date formatted as desired in there.

View solution in original post

18 REPLIES 18

Ajay Singh2
Tera Contributor

it is taking current system date and time.

Hello @Ajay Singh2 

 

 

var gdt = new GlideDateTime();
var date=gdt.getDate();
var time = gdt.getTime();

var dateMod = date.getByFormat('yyyyddMM');
var timeMod = time.getByFormat('HHmmss');
var res = dateMod +'-' +timeMod;
gs.info(res);

 

use this working for me

 

Plz mark my solution as Accept, If you find it helpful.

 

Regards,

Samaksh

I think GlideDateTime will not work in client script. It will only work in Server side. Please advise for client script.

Hello @Ajay Singh2 

 

You have to use Script Include and Call it into the Client Script using GlideAjax.

 

Plz mark my solution as Accept, If you find it helpful.

 

Regards,

Samaksh

Hello @Ajay Singh2 

 

Your expected output :-

 

Screenshot 2023-11-04 at 1.30.59 AM.png