ANS-1816 · SUITESCRIPT DEVELOPMENT

What is the Difference Between ‘datetime’ and ‘datetimetz’ in nlapiStringToDate?

Understanding how the 'datetime' and 'datetimetz' formats handle seconds during date string conversion in NetSuite SuiteScript.

Short answer

When using nlapiStringToDate in NetSuite SuiteScript, the key distinction between 'datetime' and 'datetimetz' lies in their handling of seconds. The 'datetimetz' format preserves the seconds component of the date string during conversion, ensuring full time precision. Conversely, the 'datetime' format omits or truncates the seconds, resulting in a less precise time value.

Scenario

Developers working with NetSuite SuiteScript often encounter the nlapiStringToDate function for converting date strings into NetSuite date objects. A common point of confusion arises when choosing between the 'datetime' and 'datetimetz' format specifiers, as their precise impact on the resulting date object's time component is not always immediately clear. This distinction is crucial for maintaining data precision, especially when dealing with time-sensitive operations.

Solution

The fundamental difference between the 'datetime' and 'datetimetz' format specifiers within the nlapiStringToDate function pertains to how they handle the seconds component of a date string during conversion.

The 'datetimetz' format ensures that the seconds value present in the input date string is retained and included in the resulting NetSuite date object. This provides a higher level of time precision.

In contrast, the 'datetime' format does not preserve the seconds during the conversion process. When using 'datetime', the seconds component of the input string will be omitted or truncated, leading to a less granular time representation in the output date object.

Expert NetSuite Support

Need help with this NetSuite issue?

SuiteScript Development consulting and configuration support

Talk to a consultant