How to convert the any date time to yyyy-MM-dd "2024-12-30 08:14:54

shashanksha
Tera Contributor

How to convert the any date time format  into yyyy-MM-dd "2024-12-30 08:14:54" this format. My requirement is that i want the datetime to be in System(yyyy-MM-dd) format.

 

Thanks,

Shashank Sharma

5 REPLIES 5

Shruti
Mega Sage
Mega Sage
var gdt = new GlideDateTime();
gdt.setDisplayValue("26/12/2024 00:00:00", "dd/MM/yyyy HH:mm:ss");
gs.info(gdt.getDisplayValueInternal());

Juhi Poddar
Kilo Patron

Hello @shashanksha 

Please refer to the script below:

var gdt = new GlideDateTime();
gdt.setDisplayValue("26/12/2024 00:00:00", "dd/MM/yyyy HH:mm:ss");
gs.print(gdt.getDisplayValueInternal());

Result:

JuhiPoddar_0-1731487935447.png

 

"If you found my answer helpful, please like and mark it as the "accepted solution". It helps others find the solution more easily and supports the community!"

 

Thank You
Juhi Poddar

GlideFather
Tera Patron

 

Try to get getByFotmat(); just be aware that using GlideDate (it requires format "dd-MM-yyyy") while GlideDateTime also requires the time ("dd-MM-YYYY hh:mm:ss")


Example:
var gdt = new GlideDateTime("2011-08-31 08:00:00");
var gtime1 = new GlideTime();
gtime1.setValue("00:00:20");
gdt.add(gtime1);
var gtime2 = gdt.getTime();
gs.info(gtime2.getByFormat('hh:mm:ss'));

 

 

More details HERE:

Screenshot 2024-11-13 at 09.16.22.png

———
/* If my response wasn’t a total disaster ↙️ drop a Kudos or Accept as Solution ↘️ Cheers! */


shashanksha
Tera Contributor

Hello,

Actually the exact requirement is to convert the any date time format  into yyyy-MM-dd "2024-12-30 08:14:54" this format. My requirement is that i want the datetime to be in System(yyyy-MM-dd) format.