ITSM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-27-2024 02:14 AM
I have one date time field which is in format "01/27/2024 15:40:20" and i want it to show like "2024/01/27 15:40:20"
How to achieve this
Thanks in advance.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-27-2024 02:26 AM
Hello @ayushigupta9 ,
Did you check with GlideDateTime object.
var dateTimeValue = current.your_date_time_field;
var gdt = new GlideDateTime();
gdt.setDisplayValue(dateTimeValue);
var formatted = gdt.getDisplayValue('yyyy/MM/dd HH:mm:ss');
current.formatted_date_time_field = formatted;
If my answer solve your query kindly accept and mark as correct and helpful.
Regards,
Cb
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-27-2024 02:51 AM
I have used this code as Before BR but it is showing below error
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-27-2024 03:55 AM
Please use the below Code which is working fine in the Background Script .
var gdt = new GlideDate();
gs.print(gdt);
Regards,
Rudransh.
var date = gdt.getByFormat('dd/MM/yyyy');
gs.print(date);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-27-2024 06:37 AM
You can use
var d = new Date();
// Format the date into YYYY-MM-DD HH:MM:SS
var formattedDate = d.getFullYear() + '-' +
('0' + (d.getMonth() + 1)).slice(-2) + '-' + // Months are zero-based
('0' + d.getDate()).slice(-2) + ' ' +
('0' + d.getHours()).slice(-2) + ':' +
('0' + d.getMinutes()).slice(-2) + ':' +
('0' + d.getSeconds()).slice(-2);
// Set the formatted date to the field
g_form.setValue('accept_time_mdm', formattedDate);
or you may check -
Please appreciate the efforts of community contributors by marking appropriate response as correct answer and helpful, this may help other community users to follow correct solution in future.
Regards,
CB