Can we convert DateTime Filed value into different DateTime format?

MayurGavhane
Tera Contributor

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.

MayurGavhane_0-1692598841251.png

MayurGavhane_1-1692599021481.png

MayurGavhane_2-1692599107853.png

 

 

 

8 REPLIES 8

Samaksh Wani
Giga Sage
Giga Sage

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

Hi Samaksh,

This is my script-

Could you check and tell me how can I use '.getFormatBy()'.

Script Include-

var cab_review_name = this.getParameter('sysparm_cabreviewname');
        var obj = new GlideRecord('cmn_schedule_span');
        obj.get(cab_review_name);
        obj.query();
        while (obj.next()) {
            var iso = obj.start_date_time;
}

Hello @MayurGavhane 

 

var cab_review_name = this.getParameter('sysparm_cabreviewname');
        var obj = new GlideRecord('cmn_schedule_span');
        obj.get(cab_review_name);
        obj.query();
        while (obj.next()) {
            var iso = obj.start_date_time;
            iso.getByFormat("dd-MMM-yyyy HH:MM:SS");
            gs.info(iso);
}

Harish Bainsla
Tera Sage
Tera Sage

// 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);