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