How to convert the any date time to yyyy-MM-dd "2024-12-30 08:14:54
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-13-2024 12:37 AM - edited 11-13-2024 01:34 AM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-13-2024 12:41 AM
var gdt = new GlideDateTime();
gdt.setDisplayValue("26/12/2024 00:00:00", "dd/MM/yyyy HH:mm:ss");
gs.info(gdt.getDisplayValueInternal());
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-13-2024 12:54 AM
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:
"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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-13-2024 01:16 AM - edited 11-13-2024 01:18 AM
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:
/* If my response wasn’t a total disaster ↙️ ⭐ drop a Kudos or Accept as Solution ✅ ↘️ Cheers! */
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-13-2024 01:36 AM
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.