{"revision":"c10276e953456835cdbb1f3a60d58ae1980be353","document":{"id":37798,"path":"order-management/quote-tm-date-time-field-behavior.md","title":"Date and time field fields","bundle":null,"doc_type":null,"release":"australia","body":"\n# Date and time field fields\n\nReference for how date and time fields behave in CPQ ServiceNow Quote Experience rules and scripts, including comparison operators, null handling, and supported aggregate functions.\n\n## Date and time fields in quoting\n\nDate and time fields in CPQ serve two primary purposes in a quoting context.\n\n-   **Term calculations**\n\n    Calculate contract terms, start and end dates, renewal dates, and subscription lengths. Blank or null date values can affect term accuracy — use system defaults such as the current date, or flag missing values using error messages in rules.\n\n-   **Audit events**\n\n    Track activities such as quote creation, pricing changes, and approval events. Missing dates indicate incomplete data and should be flagged for review.\n\n\n## Date and time formats\n\nServiceNow Quote Experience supports the following date and time formats.\n\n|Format type|Format pattern|Example|\n|-----------|--------------|-------|\n|Date only|`YYYY-MM-DD`|`2024-11-07`|\n|Date and time|`YYYY-MM-DDTHH:MM:SS`|`2024-10-22T14:30:00`|\n|UTC \\(stored format\\)|`YYYY-MM-DDTHH:MM:SSZ`|`2024-10-22T14:30:00Z`|\n\nDate-only fields are time-zone agnostic. All date and time values are stored in Coordinated Universal Time \\(UTC\\) to avoid time-zone discrepancies. Administrators can choose whether to include the time component when configuring a date/time field.\n\nIn the ServiceNow Quote Experience layout, the field type value that controls display behavior is:\n\n-   `\"type\":\"Date\"` — displays only the date component.\n-   `\"type\":\"DateTime\"` — displays both date and time components.\n\n## Null and blank date behavior in scripts\n\nBlank and null date values follow specific comparison rules in ServiceNow Quote Experience scripts and rule conditions.\n\n-   Blank/null dates compare as `false` unless compared directly to another blank value.\n-   The default value of a date field is empty \\(null\\) unless a default is specified in the field configuration.\n\nThe following examples show blank date comparison outcomes.\n\n|Expression|Result|Explanation|\n|----------|------|-----------|\n|`date123 = \"\"`|`true`|A blank date compared to a blank string evaluates to true.|\n|`date123 != \"\"`|`false`|A blank date compared as not-equal to blank evaluates to false.|\n\n## Supported comparison operators\n\nThe following comparison operators are supported for date and time field values in rule conditions and scripts.\n\n|Operator|Behavior|\n|--------|--------|\n|`<`|Less than. Always evaluates to `false` when either operand is blank or null.|\n|`<=`|Less than or equal to. Always evaluates to `false` when either operand is blank or null.|\n|`>`|Greater than. Always evaluates to `false` when either operand is blank or null.|\n|`>=`|Greater than or equal to. Always evaluates to `false` when either operand is blank or null.|\n|`=`|Equal to. Evaluates to `true` only when both operands are blank.|\n|`!=`|Not equal to. Evaluates to `false` when either operand is blank or null.|\n\n## Aggregate functions for date fields\n\nThe following aggregate functions are supported for date field values. Use these in determination rule scripts to calculate date values across transaction lines.\n\n|Function|Behavior|Notes|\n|--------|--------|-----|\n|`Max`|Returns the latest date in the set.|Supported.|\n|`Min`|Returns the earliest date in the set.|Supported.|\n|`Count`|Counts non-empty date values in the set.|Supported.|\n|`Sum`|Not applicable to date values.|Not recommended — may trigger compile-time errors.|\n|`Avg`|Not applicable to date values.|Not recommended — may trigger compile-time errors.|\n\n## Date calculation script example\n\nThe following script calculates the difference between a start date and an end date in months and days, and stores the result in a subscription term field. Use this pattern in a determination rule action to populate a summary field from two date inputs.\n\n```\n// Calculates the difference between start and end dates in months and\n// days. Stores the result in Subscription Term (Months).\n\nvar yearsDiff =\n  txn.custom.endDate.getFullYear() - txn.custom.startDate.getFullYear();\nvar monthsDiff =\n  txn.custom.endDate.getMonth() - txn.custom.startDate.getMonth();\nvar totalMonths = yearsDiff * 12 + monthsDiff;\n\nvar startDay = txn.custom.startDate.getDate();\nvar endDay = txn.custom.endDate.getDate();\nvar daysInMonth = new Date(\n  txn.custom.endDate.getFullYear(),\n  txn.custom.endDate.getMonth() + 1,\n  0\n).getDate();\nvar dayFraction = (endDay - startDay + 1) / daysInMonth;\n\ntotalMonths += dayFraction;\nreturn Math.floor(totalMonths * 1000) / 1000;\n```\n\n**Parent Topic:**[Quote transaction fields](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/order-management/quote-tm-fields.md)\n\n**Related topics**  \n\n\n[Quote transaction fields](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/order-management/quote-tm-fields.md)\n\n[Transaction-level system fields](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/order-management/quote-tm-header-level-system-fields.md)\n\n[Transaction line-level system fields](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/order-management/quote-tm-line-level-system-fields.md)\n\n[Create a transaction field](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/order-management/quote-tm-create-field.md)\n\n"}}