确定SPARQL中日期时间的星期几 [英] Determining Day Of Week For Datetime in SPARQL

查看:81
本文介绍了确定SPARQL中日期时间的星期几的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个图表正在尝试按星期几过滤报告。例如,我希望找到在星期二发生的所有实例。有没有办法将datetime字段格式化为星期几,或者直接在datetime字段上按星期几过滤?

I have a graph I am trying to filter for a report by day of week. For instance, I wish to find all the instances where they occurred on a Tuesday. Is there a way to either format the datetime field into day of week or filter by day of week directly on the datetime field?

推荐答案

如果您提供了一些背景知识,也可以确定标准SPARQL中的星期几。查询需要在您的日期之前的参考日期以及该日期的星期几。

You can also determine the day of week in standard SPARQL if you provided a bit of background knowledge. The query needs a reference date preceding your dates and the day of week at this date.

PREFIX xsd:  <http://www.w3.org/2001/XMLSchema#>

SELECT ?date ?dayName
WHERE {
  # Sample dates
  VALUES ?date {
    "1961-08-04"^^xsd:date
    "1986-04-03"^^xsd:date
  }
  # Compute days since a reference date
  # This works in Virtuoso, which returns the difference in days.
  # For example, Fuseki returns xsd:duration instead.
  BIND (?date - "1900-01-01"^^xsd:date AS ?days)
  # Compute modulo by 7 without a modulo operator
  BIND (floor(?days - (7 * floor(?days/7))) AS ?mod)
  VALUES (?mod ?dayName) {
         (0    "Monday") # 1900-01-01 was Monday
         (6    "Tuesday")
         (5    "Wednesday")
         (4    "Thursday")
         (3    "Friday")
         (2    "Saturday")
         (1    "Sunday")
  }
}

这篇关于确定SPARQL中日期时间的星期几的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆