---
schema_version: "1"
id: 03c303d060c07ae184aff0e28863f79ee0234f1258ca459dd3d1e29b7735af8e
title: toDateTime(string, format)
collection: developer
version: current
locale: en-us
portal_url: https://docs.salesforce.com/developer/current/en-us/analytics/bi_dev_guide_saql/guides/concept/bi-saql-functions-timezone-datetime-string.md
canonical_url: https://developer.salesforce.com/docs/analytics/bi-dev-guide-saql/guide/bi-saql-functions-timezone-datetime-string.html
source_site: developer.salesforce.com
content_type: documentation
content_hash: c39ed3e5f4581c7a1081ecd8fff9d2d89e5e692bad5bc1454e0b46374cf25176
products:
  - Analytics SAQL Developer Guide
  - analytics
---

# toDateTime(string, format)

Converts a date in string format to a `DateTime` type. _“format”_ specifies the date format and can be any valid date format.

```nolang
q = foreach q generate toDateTime('CloseDate',"yyyy/MM/dd") as DateTime;
```

For the allowed formats, see [Date Formats](https://developer.salesforce.com/docs/analytics/bi-dev-guide-saql/reference/bi-date-formats.md).

If a _format_ argument isn’t provided, the function uses the format `yyyy-MM-dd HH:mm:ss`. _format_ is only valid for converting date string values. It isn’t valid for converting _epoch_ numerical values.
