Can we convert DateTime Filed value into different DateTime format?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-20-2023 11:25 PM
Hi All,
I am getting Date and Time using XML but field type is Formatter -"start_date_time"
And it is showing in string format so is there any way I can convert into diff DateTime format without using array.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-20-2023 11:26 PM
Hello @MayurGavhane
You can do this by writing script :-
use .getFormatBy()
Plz Mark my Solution as Accept and Give me thumbs up, if you find it helpful.
Regards,
Samaksh
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-20-2023 11:32 PM
Hi Samaksh,
This is my script-
Could you check and tell me how can I use '.getFormatBy()'.
Script Include-
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-20-2023 11:56 PM
Hello @MayurGavhane
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-20-2023 11:56 PM
// Assuming 'current' is the current record being processed (change this as needed)
var dateTimeField = current.getValue('datetime_field'); // Replace 'datetime_field' with your actual field name
var inputFormat = 'yyyy-MM-dd HH:mm:ss'; // Replace with the current format of your datetime_field
var outputFormat = 'MM/dd/yyyy hh:mm a'; // Replace with the desired output format
var inputDateTime = new GlideDateTime();
inputDateTime.setDisplayValue(dateTimeField, inputFormat);
var outputDateTime = inputDateTime.getDisplayValue(outputFormat);
gs.info("Original DateTime: " + dateTimeField);
gs.info("Converted DateTime: " + outputDateTime);