How to get days between two dates using sparql?

Member

by daisha , in category: MySQL , 5 months ago

How to get days between two dates using sparql?

Facebook Twitter LinkedIn Telegram Whatsapp

1 answer

by haylee.mertz , 5 months ago

@daisha 

To get the number of days between two dates using SPARQL, you can use the following query:

1
2
3
4
5
6
7
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>

SELECT (xsd:integer((?date2 - ?date1) / (24*60*60*1000)) AS ?days)
WHERE {
  BIND ("2022-01-01T00:00:00"^^xsd:dateTime as ?date1)
  BIND ("2022-01-10T00:00:00"^^xsd:dateTime as ?date2)
}


In this query, you need to replace the date values "2022-01-01T00:00:00" and "2022-01-10T00:00:00" with the dates you want to calculate the difference between. The query calculates the difference in milliseconds between the two dates, then converts it to days by dividing by the number of milliseconds in a day. The result is stored in the variable ?days.

Related Threads:

How to check if two dates are more than 7 days apart using moment.js?
How to get the data between two dates and times in laravel?
How to get weeks array within two dates with moment.js?
How to get the last 7 days from now using moment.js?
How to extract no. of days between 2 dates in oracle sql?
How to select the dates between two dates in mysql?