how to set due date 2 hours from current date/time using client script

jahnavi chanda
Tera Contributor

Hi All,

I have a requirement, based on the type selection I need to auto populate due date 2 hours from current date/time using client script How to do it please any one help me.

Thanks in advance!

15 REPLIES 15

aditya174
Tera Guru

Hi @jahnavi chanda , please use this script

// Get the current date/time
var now = new Date();

// Calculate the due date/time by adding 2 hours to the current date/time
var dueDate = new Date(now.getTime() + (2 * 60 * 60 * 1000));

// Set the value of the due date field on the current record
g_form.setValue('due_date', dueDate);

 

Please mark m answer correct/helpful if it helps to solve your problem.

 

Regards,

Aditya

Hi @aditya174, , Thank you!

By using above script it is updating due date as Wed Apr 12 2023 14:03:53 GMT+0530 (India Standard Time)

But I want this format(12/04/2023 14:03:53) . Do you have any idea. Could you please help with this.

HI @jahnavi chanda ,

Try this one

var now = new GlideDateTime();

// Calculate the due date/time by adding 2 hours to the current date/time
var dueDate = new GlideDateTime(now.getTime() + (2 * 60 * 60 * 1000));

// Set the value of the due date field on the current record
g_form.setValue('due_date', dueDate);

 

If my answer has helped with your question, please mark my answer as an accepted solution and give a thumbs up.

 

Regards,

Aditya

Hi @jahnavi chanda , please find the updated script in reply to this message of yours, now the date is coming in the format you wanted.

 

If my answer has helped with your question, please mark my answer as an accepted solution and give a thumbs up.

 

Regards,

Aditya