IsDateTime(value) Last updated: 26. Nov 2024

Checks if value is a datetime type.

Parameters

Name Type Description
value object Value to try to check if is a datetime that can be converted

Returns

True if the value is or can be converted to a datetime.

Example

Code example (JS)

JS is normal JavaScript either running in the browser or on the Docly™ server.
let text = "2023-01-01T13:45"; // a datetime
let text2 = "20230101"; // not a datetime

if (docly.IsDateTime(text)) {
    console.log("Text is a datetime!");
}
if (!docly.IsDateTime(text2)) {
    console.log("Text2 is not a datetime!");
}

/*
    Formats supported:           
      "yyyy-MM-ddTHH:mm:ss.FFFFFFFZ",  // Full ISO with timezone
      "yyyy-MM-ddTHH:mm:ssZ",          // ISO with seconds
      "yyyy-MM-ddTHH:mmZ",             // ISO without seconds
      "yyyy-MM-ddTHH:mm:ss.FFFFFFF",   // Full ISO without timezone
      "yyyy-MM-ddTHH:mm:ss",           // Basic datetime
      "yyyy-MM-dd HH:mm:ss",           // Space separated
      "yyyy-MM-dd HH:mm"               // Basic datetime without seconds

*/