# Operating on date class variables

**URL:** <https://datashield.discourse.group/t/operating-on-date-class-variables/260>\
**Category:** Beginner Support\
**Created:** [22 July 2020 09:20 UTC](https://datashield.discourse.group/t/operating-on-date-class-variables/260 "2020-07-22T09:20:44Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![jack.lyons](https://avatars.discourse-cdn.com/v4/letter/j/eada6e/32.png) [@jack.lyons](https://datashield.discourse.group/u/jack.lyons)\
**Post date:** [22 July 2020 09:20 UTC](https://datashield.discourse.group/t/operating-on-date-class-variables/260/1 "2020-07-22T09:20:44Z")

</div>

I can’t find anything for working with date and timestamp data classes. I need to analyse a numeric variable for a subset of the data in which the date is between two values. I’ve tried to create a subset with:

`ds.dataFrameSubset(df.name = 'D', V1.name = 'D$DATE', Boolean.operator = '<=', V2.name = '2019-01-31', newobj = 'JAN19')`

But this is “invalid in at least one source” and “there are studysideMessage(s) on this datasource”, I don’t have any more info in these studysideMessages (I should note that `D$DATE` is class `Date` and ranges from 2019-01-01 to 2020-06-30). Any idea on how to approach with this?

---

<div class="post-metadata">

**Author:** ![jack.lyons](https://avatars.discourse-cdn.com/v4/letter/j/eada6e/32.png) [@jack.lyons](https://datashield.discourse.group/u/jack.lyons)\
**Post date:** [22 July 2020 13:29 UTC](https://datashield.discourse.group/t/operating-on-date-class-variables/260/2 "2020-07-22T13:29:53Z")

</div>

I found a solution if anyone is interested: log into the Opal servers via your browser and go to ‘Administration’, then ‘DataSHIELD’, under ‘Methods’ select ‘Assign’, click ‘Add Method’ and add base::substring to the listed methods; you’ll need to do this on each server; in you R environment use

`ds.asCharacter(x.name = "D$DATE", newobj = "chardate")`

`ds.assign(toAssign = "as.numeric(substring(chardate, 1, 4))", newobj = 'YEAR')`

`ds.assign(toAssign = "as.numeric(substring(chardate, 6, 7))", newobj = 'MONTH')`

`ds.cbind(x = c("D", "YEAR", "MONTH"), newobj = "D1")`

`ds.dataFrameSubset(df.name = "D1", V1.name = "D1$YEAR", Boolean.operator = "==", V2.name = "2020", newobj = "D2020")`

`ds.dataFrameSubset(df.name = "D2020", V1.name = "D2020$MONTH", Boolean.operator = "==", V2.name = "1", newobj = "DJAN2020")`

---

<div class="post-metadata">

**Author:** ![demetris.avraam](https://avatars.discourse-cdn.com/v4/letter/d/439d5e/32.png) [@demetris.avraam](https://datashield.discourse.group/u/demetris.avraam)\
**Post date:** [28 July 2020 16:28 UTC](https://datashield.discourse.group/t/operating-on-date-class-variables/260/3 "2020-07-28T16:28:37Z")

</div>

Hi Jack,

Yes, that is the solution, however I want to note that the DataSHIELD users do not have the rights to add any methods using your suggested way. Only the people who have admin rights (e.g. data managers) can change/add something on the server-side. 🙂
