---
schema_version: "1"
id: 325ed0b1094a338a60e23499d0678b7366d47379492cd12922f8c40d68625a04
title: date_to_string(DateTime | DateOnly, 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-date2string.md
canonical_url: https://developer.salesforce.com/docs/analytics/bi-dev-guide-saql/guide/bi-saql-functions-timezone-date2string.html
source_site: developer.salesforce.com
content_type: documentation
content_hash: abd493a5e3a3e6ca47a56f34e7d3b0abecd0c1a7842d87a44e46700a15e6d58d
products:
  - Analytics SAQL Developer Guide
  - analytics
---

# date_to_string(DateTime | DateOnly, format)

Converts a date to a string.

This function takes a `DateTime`, `DateOnly`, or `now()` as its first argument. For the allowed formats, see the Date Formats section in [Date Formats](https://developer.salesforce.com/docs/analytics/bi-dev-guide-saql/reference/bi-date-formats.md).

Use `date_to_string()` to display the close date for your opportunities in the format `yyyy-MM-dd.`. `CloseDate` must be a `DateTime` or `DateOnly` type.

```nolang
q = foreach q generate date_to_string('CloseDate', "yyyy-MM-dd") as 'Close Date';
```

If `CloseDate` is a `Date` type, convert it to a `DateOnly` type with `toDate()`.

```nolang
q = foreach q generate date_to_string(toDate('CloseDate', "yyyy-MM-dd"), "yyyy-MM-dd") as 'Close Date';
```
