Welcome to Community Week 2025! Join us to learn, connect, and be recognized as we celebrate the spirit of Community and the power of AI. Get the details  

Calculate seconds in timer activity

priyanka1028
Tera Contributor

Hi Team,

 

How to calculate seconds based on start date and end date in format (yyyy-mm-dd) in timer activity of workflow?

Please help me by providing your answer.

2 ACCEPTED SOLUTIONS

shloke04
Kilo Patron

Hi @priyanka1028 ,

 

Select "Script" as an value within the attribute "Timer based on" within your Timer activity within a workflow as shown below:

shloke04_0-1708426537522.png

 

Now make use of below script to get the seconds between your date attributes:

// Set 'answer' to the number of seconds this timer should wait
var start = new GlideDateTime("Pass your value here.");
var end = new GlideDateTime("Pass your value here.");

// Duration in seconds

answer = gs.dateDiff(start, end, true); // returns the number of seconds as String

 

Hope this helps. Please mark the answer as correct/helpful based on impact.

Regards,
Shloke

View solution in original post

@priyanka1028  - In case if you want to pass a value from an attribute instead of hardcoding the date value in script above, then you would need to follow below steps:

1. Do a glide Record on your table and retrieve the value of date attributes.

2. Pass that into line 1 and 2 in script shared above.

3. Rest component remains same.

Hope this helps. Please mark the answer as correct/helpful based on impact.

Regards,
Shloke

View solution in original post

3 REPLIES 3

shloke04
Kilo Patron

Hi @priyanka1028 ,

 

Select "Script" as an value within the attribute "Timer based on" within your Timer activity within a workflow as shown below:

shloke04_0-1708426537522.png

 

Now make use of below script to get the seconds between your date attributes:

// Set 'answer' to the number of seconds this timer should wait
var start = new GlideDateTime("Pass your value here.");
var end = new GlideDateTime("Pass your value here.");

// Duration in seconds

answer = gs.dateDiff(start, end, true); // returns the number of seconds as String

 

Hope this helps. Please mark the answer as correct/helpful based on impact.

Regards,
Shloke

@priyanka1028  - In case if you want to pass a value from an attribute instead of hardcoding the date value in script above, then you would need to follow below steps:

1. Do a glide Record on your table and retrieve the value of date attributes.

2. Pass that into line 1 and 2 in script shared above.

3. Rest component remains same.

Hope this helps. Please mark the answer as correct/helpful based on impact.

Regards,
Shloke

Thank you so much @shloke04 

This one is going to help me a lot