How to convert the utcdatetime to string in x++?
Purpose: Whenever a user creates a record with a UTCDatetime value, the exact time may not be displayed correctly in SQL. To retrieve the precise time, we convert the UTCDatetime value to a string format.
High Resolution steps
- Create the field with datatype utcdatetime
- Create a runnable class to convert utcdatetime to string.
Detailed Resolution steps:
Step 1: Create the utc datetime field in the table

Step 2 :Create a runnable class to convert the utcdatetime to string
Code Snippet:
internal final class MANDateClass
{
///
/// Class entry point. The system will call this method when a designated menu
/// is selected or when execution starts and this class is set as the startup class.
///
/// The specified arguments.
public static void main(Args _args)
{
MANDateClass manDateClass = new MANDateClass();
manDateClass.expirydatetime();
}
public void expirydatetime()
{
MANDepartmentTable manDepartmentTable;
while select manDepartmentTable
{
utcdatetime utcExpiryDate =manDepartmentTable.PeriodCompletion;
str expiryDate = DateTimeUtil::toStr(DateTimeUtil::applyTimeZoneOffset(utcExpiryDate,
DateTimeUtil::getUserPreferredTimeZone()));
info(strFmt('Value (after convert) = %1',expiryDate ));
}
}
}
Code:

Output:
- In SQL,the below screenshot the utcdatetime will not show the exact time

2. After running the runnable class, the exact utcdatetime is shown.
