The CreatorCon Call for Content is officially open! Get started here.

How to convert 「yyyy/m/d」(shortform) to 「yyyy/mm/dd」(Long form)

masaya8989
Tera Contributor

I'm trying to import CSV file to ServiceNow table.

I have date value in CSV fille which format is「yyyy/mm/d」.

I want to use this date value in long format(yyyy/mm/dd) in ServiceNow.

So I want to know the way to convert 「yyyy/mm/d」(shortform) to 「yyyy/mm/dd」(Long form).

I know the way to use import set but I don't understand the script.

I try some code like below but it doesn't work. 

Please give me some advice.

masaya8989_0-1705063428604.png

 

1 REPLY 1

Iraj Shaikh
Mega Sage

Hi @masaya8989 

 

// Assuming 'source.u_date' is the field in the import set with the date in 'yyyy/m/d' format
// and 'target.date_field' is the field in the target table where you want to store the date in 'yyyy/mm/dd' format

var dateString = source.u_date; // Replace 'u_date' with the actual source field name
if (dateString) {
    var gdt = new GlideDateTime();
    gdt.setValue(dateString); // Parse the date string into GlideDateTime object
    var formattedDate = gdt.getByFormat("yyyy/MM/dd"); // Format the date
    target.date_field = formattedDate; // Replace 'date_field' with the actual target field name
}

 

 

Please mark this response as correct or helpful if it assisted you with your question.