We're reclaiming inactive PDIs to keep them available for active builders. Learn what's changing, who's affected, and how to protect your work. Read More

How to parse inbound email date value formatted in yyyy-mm-dd to ServiceNow date variable

Not applicable

Hi There,

 

We are receiving inbound mail to ServiceNow having date mentioned in the format "Date of Joining: 2024-06-29" (yyyy-mm-dd). 

and we are trying to convert using below script

"var DOJ_obj=new GlideDateTime(DOJ.toString());"
 
but system is picking random date instead.
 
Thanks,
Tejas
2 REPLIES 2

SN_Learn
Mega Patron

Hi @Community Alums ,

 

Could you please provide some screenshots of the issue and the field where you want to set the date/time?

 

----------------------------------------------------------------
Mark this as Helpful / Accept the Solution if this helps.

Its_Azar
Mega Sage

Hi there @Community Alums 

 

Guess u can use the following script to ensure proper conversion

 

 

var emailDate = "2024-06-29";  // Extracted date from the email
var dateParts = emailDate.split("-");
var formattedDate = dateParts[1] + "/" + dateParts[2] + "/" + dateParts[0];
var DOJ_obj = new GlideDateTime();
DOJ_obj.setDisplayValue(formattedDate);

 

 

This script splits the inbound date string, reorders it to the mm/dd/yyyy format required by GlideDateTime, and then sets it as a date object. guess this will nmake correct date is picked up by the system.

 

If this helps kindly accept the answer. thanks

 

 

☑️ If this helped, please mark it as Helpful or Accept Solution so others can find the answer too.

Kind Regards,
Azar
Serivenow Rising Star
Developer @ KPMG.