Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
Switch services using the Version drop-down list. Learn more about navigation.
Applies to: ✅ Microsoft Fabric ✅ Azure Data Explorer ✅ Azure Monitor ✅ Microsoft Sentinel
Converts the input to a datetime scalar value.
Note
- To learn more about supported data and time formats and syntax, see The datetime data type.
- When possible, use datetime literals instead of the
todatetime()function.
Syntax
todatetime(value)
Learn more about syntax conventions.
Parameters
| Name | Type | Required | Description |
|---|---|---|---|
| value | scalar | ✔️ | The value to convert to datetime. |
Returns
If the conversion is successful, the result is a datetime value.
Else, the result is null.
Example
The following example converts a date and time string into a datetime value.
print todatetime("2015-12-31 23:59:59.9")
The following example compares a converted date string to a datetime value.
print todatetime('12-02-2022') == datetime('12-02-2022')
Output
| print_0 |
|---|
| true |
Related content
- make-datetime function
- Scalar function types at a glance
- The datetime data type
- datetime_add function
- Datetime / timespan arithmetic
- totimespan function