How to convert 「yyyy/m/d」(shortform) to 「yyyy/mm/dd」(Long form)
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-12-2024 04:47 AM
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.
1 REPLY 1
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-13-2024 12:49 AM
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.