flow designer script is not working

chandan86patra
Tera Contributor
Hi All , I am getting the value 1978-06-01 in a Flow Designer variable. I want to create another variable to calculate how many days there are between 1978-06-01 and today's date. Could you please provide the Flow Designer script? I am tried this script but it is not working var inputDate = fd_data.flow_var.date_of_birth.toString(); var startDate = new GlideDateTime(inputDate + " 00:00:00"); var todayDateOnly = new GlideDate().getValue(); var today = new GlideDateTime(todayDateOnly + " 00:00:00"); var difference = today.getNumericValue() - startDate.getNumericValue(); var days = Math.floor(difference / (1000 * 60 * 60 * 24)); return days; Thanks ,
1 ACCEPTED SOLUTION

VaishnaviK3009
Kilo Sage

Hi @chandan86patra ,

Flow Designer has no built-in action for days between two dates, so use an inline script in Set Flow Variables:

  1. Create an Integer flow variable (e.g. days_since_dob).
  2. In Set Flow Variables, select it, click the script icon (</>) on the value field, and paste:
 
var dob = new GlideDate();
dob.setValue(fd_data.flow_var.date_of_birth.toString());
var today = new GlideDate();
return Math.round((today.getNumericValue() - dob.getNumericValue()) / 86400000);

Using GlideDate for both dates avoids the time and time-zone offsets that usually break GlideDateTime calculations.

If it fails, make sure date_of_birth is populated by an earlier step, and check the error in the execution details.

 

Mark this as Helpful if it clarifies the issue.
Accept the solution if this answers your question.

Regards,
Vaishnavi
Technical Consultant

View solution in original post

3 REPLIES 3

yashkamde
Giga Sage

Hello @chandan86patra ,

 

In your script GlideDateTime expects the format yyyy-MM-dd HH:mm:ss, but fd_data.flow_var.date_of_birth.toString() often includes unexpected formatting or spaces depending on the variable type.

 

try this script :

var inputDate = fd_data.flow_var.date_of_birth.toString(); 

// Initialize GlideDateTime objects for both dates
var startDate = new GlideDateTime(inputDate + " 00:00:00");
var todayDate = new GlideDateTime(); // This automatically fetches current date and time

// Subtract the start date from today's date to get a GlideDuration object
var duration = GlideDateTime.subtract(startDate, todayDate);

// Extract the total number of days from the duration object
var days = duration.getDayPart();

return days;

 

Also Refer this :

Calculate number days between two dates in flow designer 

 

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

VaishnaviK3009
Kilo Sage

Hi @chandan86patra ,

Flow Designer has no built-in action for days between two dates, so use an inline script in Set Flow Variables:

  1. Create an Integer flow variable (e.g. days_since_dob).
  2. In Set Flow Variables, select it, click the script icon (</>) on the value field, and paste:
 
var dob = new GlideDate();
dob.setValue(fd_data.flow_var.date_of_birth.toString());
var today = new GlideDate();
return Math.round((today.getNumericValue() - dob.getNumericValue()) / 86400000);

Using GlideDate for both dates avoids the time and time-zone offsets that usually break GlideDateTime calculations.

If it fails, make sure date_of_birth is populated by an earlier step, and check the error in the execution details.

 

Mark this as Helpful if it clarifies the issue.
Accept the solution if this answers your question.

Regards,
Vaishnavi
Technical Consultant

Ankur Bawiskar
Tera Patron

@chandan86patra 

what's your exact business requirement here?

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 10x ServiceNow MVP  ||  ✨ ServiceNow Community Leader