ClickHouse does not have built-in support for converting standard dates to Jalali dates. However, you can write a custom User-Defined Function (UDF) in ClickHouse to implement this conversion.
Here is an example UDF in ClickHouse that converts a standard date (YYYY-MM-DD) to a Jalali date:
CREATE FUNCTION to_jalali_date(date String) -> String
return strftime('%Y-%m-%d', toDateTime(concat('20', substring(date, 7, 2), '-', substring(date, 4, 2), '-', substring(date, 1, 2))))
format Str;
In this UDF, we first extract the year, month, and day components of the input date string using the substring()
function. We then concatenate them to form a DateTime string in the format expected by ClickHouse: YYYY-MM-DD HH:MM:SS
. Finally, we pass this DateTime string to the strftime()
function along with the format string %Y-%m-%d
to convert the date to Jalali format.
You can use this UDF in your queries like this:
SELECT to_jalali_date('1399/10/22') as jalali_date
-- Output: 1399-10-22
Note that this UDF assumes that the input date string is in the format DD-MM-YYYY
. If your input date format is different, you may need to modify the UDF accordingly.
Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss
Asked: 2021-04-29 11:00:00 +0000
Seen: 8 times
Last updated: Jul 14 '22