# Format Functions

This section contains format functions that uses the pattern. The table below contains the supported patterns for the format functions.

| Letter for Pattern     | Date or Time component          |
| ---------------------- | ------------------------------- |
| G                      | Era designator                  |
| y or yy or yyyy        | Year                            |
| M or MM or MMM or MMMM | Month in year                   |
| w                      | Results in week in year         |
| W                      | Results in week in month        |
| D                      | Gives the day count in the year |
| d                      | Day of the month                |
| F                      | Day of the week in month        |
| E                      | Day name in the week            |
| a                      | AM or PM marker                 |
| H                      | Hour in the day (0-23)          |
| k                      | Hour in the day (1-24)          |
| m                      | Minute in the hour              |
| s                      | Second in the minute            |

#### <mark style="color:purple;">FORMAT\_DATE(</mark>  \<expr>,  format  <mark style="color:purple;">)</mark>

Returns the date expression formatted to the specified format.

```sql
> select format_date(cast('2023-02-15' as date), 'MM');
02
```

#### <mark style="color:purple;">FORMAT\_TIMESTAMP(</mark>  \<expr>,  format  <mark style="color:purple;">)</mark>

Return the timestamp formatted according to the specified format

```sql
> select format_timestamp(current_timestamp(), 'mm');
2023
```

This section contains format functions that uses the pattern. The table below contains the supported patterns for the format functions.

<table><thead><tr><th width="161">Specifier</th><th>Description</th></tr></thead><tbody><tr><td>%a or %W</td><td>Abbreviated weekday name (Sun .. Sat) or Weekday name (Sunday .. Saturday)</td></tr><tr><td>%b or %M</td><td>Abbreviated month name (Jan .. Dec) or Month name (January .. December)</td></tr><tr><td>%d or %e</td><td>Day of the month, numeric (01 .. 31) or numeric (1 .. 31), this specifier does not support 0 as a month or day.</td></tr><tr><td>%c or %m</td><td>Month, numeric (1 .. 12), this specifier does not support 0 as a month.</td></tr><tr><td>%f</td><td>Fraction of second (6 digits for printing: 000000 .. 999000; 1 - 9 digits for parsing: 0 .. 999999999), timestamp is truncated to milliseconds</td></tr><tr><td>%H or %k</td><td>Hour (00 .. 23)</td></tr><tr><td>%h or %I</td><td>Hour (01 .. 12)</td></tr><tr><td>%j</td><td>Day of year (001 .. 366)</td></tr><tr><td>%i</td><td>Minutes, numeric (00 .. 59)</td></tr><tr><td>%S or %s</td><td>Seconds (00 .. 59)</td></tr><tr><td>%r</td><td>Time of day, 12-hour (equivalent to %h:%i:%s %p)</td></tr><tr><td>%T</td><td>Time of day, 24-hour (equivalent to %H:%i:%s)</td></tr><tr><td>%v</td><td>Week (01 .. 53), where Monday is the first day of the week and we can use %y or %x for year for using %x use 4 digits for year</td></tr><tr><td>%x</td><td>Year for the week, where Monday is the first day of the week, numeric, four digits; used with %v</td></tr><tr><td>%Y</td><td>Year, numeric, four digits</td></tr><tr><td>%y</td><td>Year, numeric (two digits), when parsing, two-digit year format assumes range 1970 .. 2069, so “70” will result in year 1970 but “69” will produce 2069</td></tr><tr><td>%%</td><td>A literal % character</td></tr></tbody></table>

#### <mark style="color:purple;">DATE\_FORMAT(</mark>  \<expr>,  format  <mark style="color:purple;">)</mark>

Return the date and timestamp formatted according to the specified format

```sql
> select date_format(cast('2024-08-26 22:38:11' as timestamp), '%m-%d-%Y %H');
08-26-2024 22
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.e6data.com/product-documentation/sql-command-reference/date-time-functions/format-functions.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
