如何在Couchbase查询中将ISO日期格式更改为字符串格式(“DD/MM/YYYY”)?

huangapple go评论60阅读模式
英文:

How to change ISO date format to string format("DD/MM/YYYY") in Couchbase query?

问题

以下是已翻译的内容:

我在文档中有一个日期属性,格式如下:

2016-09-23T18:48:11.000+00:00

我需要将此格式转换为以下格式:

“DD/MM/YYYY”

是否有任何方法可以进行转换?

我尝试了以下查询:

SELECT date_format_str("2016-09-23T18:48:11.000+00:00", '11-11-1111' ) ;

结果:

[
{
"$1": "2016-09-23T18:48:11Z"
}
]

预期结果:

"23/09/2016"

提前感谢。

英文:

I have a date attribute in document in the below format

 2016-09-23T18:48:11.000+00:00

I need to convert this format into below format

“DD/MM/YYYY”

Is there any method to convert so?

I tried the below query :-

SELECT  date_format_str("2016-09-23T18:48:11.000+00:00", '11-11-1111' ) ;

Result :-

[
    {
        "$1": "2016-09-23T18:48:11Z"
    }
]

Expected Result :-

"23/09/2016"

Thanks in advance.

答案1

得分: 3

可以使用 DATE_FORMAT_STR 完成。

对于您的示例:

SELECT DATE_FORMAT_STR("2016-09-23T18:48:11.000+0000", "DD/MM/YYYY") AS formatted_date

更多信息请参考:https://docs.couchbase.com/server/current/n1ql/n1ql-language-reference/datefun.html#fn-date-format-str

英文:

Can be accomplished with DATE_FORMAT_STR

For your example;

SELECT DATE_FORMAT_STR("2016-09-23T18:48:11.000+0000", "DD/MM/YYYY") AS formatted_date

For more information; https://docs.couchbase.com/server/current/n1ql/n1ql-language-reference/datefun.html#fn-date-format-str

答案2

得分: 3

依赖于服务器版本

检查各种选项

https://docs.couchbase.com/server/current/n1ql/n1ql-language-reference/datefun.html#date-string

SELECT DATE_FORMAT_STR("2016-09-23T18:48:11.000+0000", "%d/%m/%Y") AS formatted_date;

SELECT DATE_FORMAT_STR("2016-09-23T18:48:11.000+0000", "DD/MM/YYYY") AS formatted_date;

如果您收到版本不受支持的错误。您可以使用以下方式

SELECT CONCAT2("/",SUBSTR(date,8,2), SUBSTR(date,5,2), SUBSTR(date,0,4)) AS newdate LET date = "2016-09-23T18:48:11.000+0000";

英文:

It depends on the Server version

Check various tabs

https://docs.couchbase.com/server/current/n1ql/n1ql-language-reference/datefun.html#date-string

SELECT DATE_FORMAT_STR("2016-09-23T18:48:11.000+0000", "%d/%m/%Y") AS formatted_date;

SELECT DATE_FORMAT_STR("2016-09-23T18:48:11.000+0000", "DD/MM/YYYY") AS formatted_date;

If you get error that your version may not supported. You can use as follows

SELECT CONCAT2("/",SUBSTR(date,8,2), SUBSTR(date,5,2), SUBSTR(date,0,4)) AS newdate LET  date = "2016-09-23T18:48:11.000+0000";

huangapple
  • 本文由 发表于 2023年6月15日 18:40:53
  • 转载请务必保留本文链接:https://go.coder-hub.com/76481685.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定