# 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](/docs/analytics/bi-dev-guide-saql/guide/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.
