date_format
The date_format function is used to convert a date to a string in the format specified by format.
Syntax
date_format(string date, string format)
Parameters
| Parameter | Mandatory | Type | Description |
|---|---|---|---|
| date | Yes | DATE or STRING | The date to be converted. Formats:
|
| format | Yes | STRING | The target format. The format is a combination of time units representing year, month, day, hour, minute, and second, along with any characters.
|
Return Values
Returns a date of type STRING according to the specified format.
- If date is not of type DATE or STRING, an error is returned with the message "data type mismatch".
- If date is of type DATE or STRING but does not conform to the input format for date values, NULL is returned.
- If the date value is NULL, NULL is returned.
- If the format value is NULL, NULL is returned.
Example Code
Returns 2023-08-14.
select date_format('2023-08-14','yyyy-MM-dd'); Returns 2023-08.
select date_format('2023-08-14','yyyy-MM') Returns 20230814.
select date_format('2023-08-14','yyyyMMdd') What is your overall rating for this page?
Thank you very much for your feedback. We will continue working to improve the documentation.See the reply and handling status in My Cloud VOC.
For any further questions, feel free to contact us through the chatbot.
Chatbot