Sparql如何制作日/月总是返回2位数字
我的sparql Query中有一个日期,我想转换为日期。 因此,我确实:
BIND(CONCAT(YEAR(?dateTime), "-",MONTH(?dateTime), "-", DAY(?dateTime)) as ?date)
这部分代码有效,但返回例如2022-2-3,我希望它是2022-02-03。如果DateTime是2022-11-23,则什么都不应改变。
I have a datetime in my SPARQL-query that I want to transform to a date.
Therefore I do:
BIND(CONCAT(YEAR(?dateTime), "-",MONTH(?dateTime), "-", DAY(?dateTime)) as ?date)
This part of code works but returns for example 2022-2-3, I want it to be 2022-02-03. If the dateTime is 2022-11-23, nothing should change.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以从
年
,月
和day
函数中取回整数,并用适当的零数(转弯后)它们变成字符串):You can take the integers you get back from the
YEAR
,MONTH
, andDAY
functions and pad them with the appropriate number of zeros (after turning them into strings):@gregory-williams 给出便携式答案。另一种替代方案是f& o(xpath和xquery函数和运算符3.1)“ fn:格式-J。”
我不确定各种三分之一的覆盖范围 - apache jena jena提供
fn:format-number number
,这是问题所需的,但不是fn-format-datetime
等
https://www.w.org/www.org/tr/xpath -Functions-3/#格式 - 纳姆
https://www.w.org/tr /xpath-functions-3/#formatting-dates-and-times
例如:
fn:format-number(1,“ 000”)
返回字符串“ 001”。Apache Jena还使用
Sprintf
的C或Java语法:afn:afn:sprintf(“%03D”,1)
sprintf afn:sprintf >返回“ 001”。@gregory-williams gives a portable answer. An alternative is functions from F&O (XPath and XQuery Functions and Operators 3.1) "fn:format-...."
I'm not sure of the coverage in various triplestores - Apache Jena provides
fn:format-number
, which is needed for the question, but notfn-format-dateTime
etcSee
https://www.w3.org/TR/xpath-functions-3/#formatting-the-number
https://www.w3.org/TR/xpath-functions-3/#formatting-dates-and-times
For example:
fn:format-number(1,"000")
returns the string "001".Apache Jena also has a local extension
afn:sprintf
using the C or Java syntax ofsprintf
:afn:sprintf("%03d", 1)
returns "001".