Validation script use cases
concept australia Updated Sep 10, 2026 1 min read c_ValidateDateAndTime.md
To validate the input of all date/time fields, you can use the following in a validation script (System Definition > Validation Scripts).
Because the date/time format is hard-coded in this script, it must match your instance's date/time format. If your instance's date/time format changes, you must update your validation script.
Set the validation script's type to "glide_date_time". Then, with this validation script, if a user enters an incorrect format in a date/time field, they will receive an error message.
JavaScript
function validate (value){ if (!value) { return true; }
return (getDateFromFormat(value, 'yyyy-MM-dd HH:mm:ss') != 0);}For a comprehensive use case, see Restricting record access.
Parent Topic:Example scripts
37 lines · 1.6 KB
---
title: Validation script use cases
description: To validate the input of all date/time fields, you can use the following in a validation script \( System Definition Validation Scripts \).
locale: en-US
canonical_url: https://www.servicenow.com/docs/r/australia/api-reference/scripts/c\_ValidateDateAndTime.html
release: australia
product: Scripts
classification: scripts
topic_type: concept
last_updated: "2026-09-10"
reading_time_minutes: 1
breadcrumb: [Example scripts, Scripting, API implementation, API implementation and reference]
---
# Validation script use cases
To validate the input of all date/time fields, you can use the following in a validation script \(**System Definition** > **Validation Scripts**\).
Because the date/time format is hard-coded in this script, it must match your instance's date/time format. If your instance's date/time format changes, you must update your validation script.
Set the validation script's type to "`glide_date_time`". Then, with this validation script, if a user enters an incorrect format in a date/time field, they will receive an error message.
```javascript
function validate (value){
if (!value) {
return true;
}
return (getDateFromFormat(value, 'yyyy-MM-dd HH:mm:ss') != 0);
}
```
For a comprehensive use case, see [Restricting record access](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/scripts/useful-business-rules.md).
**Parent Topic:**[Example scripts](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/scripts/usefulScripts.md)
| title | Validation script use cases |
| description | To validate the input of all date/time fields, you can use the following in a validation script \( System Definition Validation Scripts \). |
| locale | en-US |
| canonical_url | https://www.servicenow.com/docs/r/australia/api-reference/scripts/c\_ValidateDateAndTime.html |
| release | australia |
| product | Scripts |
| classification | scripts |
| topic_type | concept |
| last_updated | 2026-09-10 |
| reading_time_minutes | 1 |
| breadcrumb | Example scriptsScriptingAPI implementationAPI implementation and reference |