Handling Date Attribute Types


I would like to know if it is possible to do queries that focus on only one part of a DateTime attribute, such as obtaining the people that were born in April, or looking at what events are taking place between 18:00 and 19:00. I did not find anything on the documentation saying how to perform those type of queries. I am not even sure if they are possible.

To get the people that were born in April in the social_network database I was trying this query:

# Get the people born in April in alphabetical order
    $birth (child: $pers) isa birth, has birth-date $bdate; 
    $bdate has month $bdatemonth; $bdatemonth 4;
    $pers isa person, has full-name $npers;
    $pers, $npers, $bdate; sort $npers;

which did not work since the attribute date does not own a subattribute month. Is there a way to do this? Or would I need to define a rule or something like that to do the work?

If you need to do this kind of access, you would need to augment your dates with further attributes at insert time.
I’d do this the following way:

  birth-date sub attribute, value datetime, // source of truth
    owns year, owns month, owns day;
  year sub attribute, value long;
  month sub attribute, value long;
  day sub attribute, value long;

In this case when you insert a birth-date you also insert some extra information that is available from your programming language’s DateTime APIs.

insert $bd isa birth-date; $bd = 2022-08-19T15:00; $bd has year 2022, has month 8, has day 19;

Hope that helps!

1 Like