How to set date/time field value to a specified time based on client's timezone ?

Harshitha7
Kilo Explorer

I have a requirement that when requested by date field in change request is changed to a specific date, then start implementation start date and end date should also be populated as follows: 

For Example:

Requested by date is changed to 12-Nov-2019.

Start Implementation start date should be populated as 12-Nov-2019 12:00:00 and start implementation end date as 12-Nov-2019 23:59:59.

I could able to set the date value but time values are setting as 07:00:00 and 18:59:59 respectively.  

I am using a BR :

var dateTime = current.requested_by_date.split(" ");
var newdate = dateTime[0];

current.setValue('start_date', newdate +" 12:00:00" );
current.setValue('end_date', newdate +" 23:59:59" );

 

3 REPLIES 3

Harsh Vardhan
Giga Patron

you can use below code. 

 

var gdt = new GlideDateTime(current.requested_by_date); 
gs.print(gdt.getDisplayValueInternal());

 

https://developer.servicenow.com/app.do#!/api_doc?v=madrid&id=r_ScopedGlideDateTimeGetDisplayValueIn...

Kajal Goti
Mega Guru

Hello,

 

Please refer below link,It would help you.

 

https://community.servicenow.com/community?id=community_question&sys_id=e44e0beddb9cdbc01dcaf3231f96...

 

Please mark as Correct and helpful,If you find any help