# Xsd:time from xsd:dateTime

**URL:** <https://community.stardog.com/t/xsd-time-from-xsd-datetime/541>\
**Category:** Support\
**Created:** [August 31, 2017, 9:41pm UTC](https://community.stardog.com/t/xsd-time-from-xsd-datetime/541 "2017-08-31T21:41:07Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![peterneorr](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.stardog.com/peterneorr/32/31_2.png) [@peterneorr](https://community.stardog.com/u/peterneorr)\
**Post date:** [August 31, 2017, 9:41pm UTC](https://community.stardog.com/t/xsd-time-from-xsd-datetime/541/1 "2017-08-31T21:41:07Z")

</div>

Are there any SPARQL methods to extract an xsd:time value from a xsd:dateTime?

I want to write queries that find dateTimes that occur before or after a given time of day. For example:

```
select * where {    
 # this doesn't work. Is there another way?
 #bind (xsd:time(now()) as ?timeOfDay)

 bind ("07:00:00Z"^^xsd:time as ?timeOfDay )
 bind (?timeOfDay > "08:00:00Z"^^xsd:time as ?testResult)
}
```

---

<div class="post-metadata">

**Author:** ![jess](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.stardog.com/jess/32/10_2.png) [@jess](https://community.stardog.com/u/jess)\
**Post date:** [August 31, 2017, 10:03pm UTC](https://community.stardog.com/t/xsd-time-from-xsd-datetime/541/2 "2017-08-31T22:03:03Z")

</div>

Hi Peter,

Afaict the only way is to extract the components manually:

```auto
select * where {
bind(now() as ?aDateTime)
bind(hours(?aDateTime) as ?h)
bind(minutes(?aDateTime) as ?m)
bind(seconds(?aDateTime) as ?s)
bind(<http://www.w3.org/2003/11/swrlb#time>(?h, ?m, ?s) as ?aTime)
}

```

```auto
+-----------------------------------------------+-------+-------+--------+--------------------------+
| aDateTime | h | m | s | aTime |
+-----------------------------------------------+-------+-------+--------+--------------------------+
| "2017-08-31T17:01:11.778-05:00"^^xsd:dateTime | 17 | 1 | 11.778 | "17:01:11.778"^^xsd:time |
+-----------------------------------------------+-------+-------+--------+--------------------------+

```

---

<div class="post-metadata">

**Author:** ![peterneorr](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.stardog.com/peterneorr/32/31_2.png) [@peterneorr](https://community.stardog.com/u/peterneorr)\
**Post date:** [September 1, 2017, 1:05am UTC](https://community.stardog.com/t/xsd-time-from-xsd-datetime/541/3 "2017-09-01T01:05:34Z")

</div>

Thanks Jess, That’s definitely a lot more verbose than what I was hoping for, but it does solves my problem. 🙂

---

<div class="post-metadata">

**Author:** ![zachary.whitley](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.stardog.com/zachary.whitley/32/94_2.png) [@zachary.whitley](https://community.stardog.com/u/zachary.whitley)\
**Post date:** [September 5, 2017, 12:37pm UTC](https://community.stardog.com/t/xsd-time-from-xsd-datetime/541/4 "2017-09-05T12:37:41Z")

</div>

You could always write a custom function that would be less verbose although it wouldn’t be portable.

---

<div class="post-metadata">

**Author:** ![jess](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.stardog.com/jess/32/10_2.png) [@jess](https://community.stardog.com/u/jess)\
**Post date:** [September 14, 2017, 1:46am UTC](https://community.stardog.com/t/xsd-time-from-xsd-datetime/541/5 "2017-09-14T01:46:53Z")

</div>

Looks like `xsd:dateTime` to `xsd:time` is a valid XPath cast. We’ll get this added along with any other missing casts.

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex030/uploads/stardog/original/2X/e/ed66b48a616f505106a4acde3c9cee7e6da9bc67.svg) [@system](https://community.stardog.com/u/system)\
**Post date:** [September 28, 2017, 1:47am UTC](https://community.stardog.com/t/xsd-time-from-xsd-datetime/541/6 "2017-09-28T01:47:10Z")

</div>

Closed on September 28, 2017, 1:47am UTC

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.
