Interested in a ServiceNow event built for developers? Registration for now[dev]26 is officially open!

How to convert date format in Flow Designer?

Kiran_25
Tera Expert

I need to convert the date format to yyyy-mm-dd in flow designer using a inline script

 

my trigger is a problem task record which contains a due_date field.

4 REPLIES 4

Dr Atul - LNG
Tera Patron

Hi @Kiran_25 

https://www.servicenow.com/community/developer-forum/format-date-in-flow-designer/m-p/2720379

 

Try the script below.

 

var dt = fd_data._1__get_catalog_variables.recording_ends_date;

 

var gd = new GlideDate();

gd.setValue(dt);

return "Recording on:" + gd.getByFormat('MM-dd-YYYY');

****************************************************************************************
Regards
Dr Atul G. - Learn N Grow Together ServiceNow Techno - Functional Trainer
LinkedIn: https://www.linkedin.com/in/dratulgrover
YouTube: https://www.youtube.com/@LearnNGrowTogetherwithAtulG
******************************************************************************************

Aylee Andersen
Kilo Sage

Hi @Kiran_25,

 

Building off of the previous comment, the code for your specific question would look something like the following:

var dueDate = fd_data.trigger.current.due_date; // grabs the due_date field from off your problem task record trigger
var gd = new GlideDate();
gd.setValue(dueDate);
var formattedDate = gd.getByFormat('yyyy-MM-dd');

 

You can find the full list of format options here:

https://docs.oracle.com/javase/10/docs/api/java/text/SimpleDateFormat.html

 

If you wanted to expand that formatting to include any timestamp information, you could do that via the following:

var dueDate = fd_data.trigger.current.due_date; // grabs the due_date field from off your problem task record trigger
var gdt = new GlideDateTime();
gdt.setValue(dueDate);
var gd = gdt.getDate(); // or getLocalDate() depending on your use case
var gt = gdt.getTime(); // or getLocalTime() depending on your use case
var formattedDate = gd.getByFormat('yyyy-MM-dd') + " " + gt.getByFormat('HH:mm:ss');

 

Helpful resources:
GlideDateTime Docs 

GlideDate Docs 

Juhi Poddar
Kilo Patron
Hi @Kiran_25 ,

Try this script:
var dueDateStr = fd_data.trigger.current.due_date;

if (dueDateStr) {
    var gdt = new GlideDateTime(dueDateStr);
    return gdt.getDate().getByFormat('yyyy-MM-dd');
}
return ''; // Return empty string if due_date is empty

Hope this helps!

 

Thank You!
Juhi Poddar

Thank You!
Juhi Poddar

yashkamde
Giga Sage

Hello @Kiran_25 ,

 

There are 2 approaches either try this script :

var dueDate = fd_data.trigger.problem_task.due_date;
if (!dueDate) return '';
var gdt = new GlideDateTime(dueDate);
return gdt.getDate().getByFormat('yyyy-MM-dd');

 

OR 
Utilized a transform function on the data pill :

Screenshot 2026-09-15 125117.png

 

If my response helped mark as helpful and accept the solution.