Help with where.function (x) with 2 conditions

hey, im a new RPA developer and i have encountered an issue with where.function(x) function…
i tried couple of things but couldnt succeed…
i have Jobject with jason arrays inside him. the Jobject is a person and in the Jobject theres all the details about him.

so i have:
Jobject → childrenUnder21 → childrenDetails → name, lastName, birthDay, familyStatus

i want to check if the child is under the age of 21 and that he is single.
im using “for each” activity and in the condition i wrote this:

Jobject_Person(“childrenUnder21”)(“childrenDetails”).Where(function (x) (datediff(“d”,x(“birthDay”), datetime.Now))/365 < 21 AndAlso x(“familyStatus”).Equals(“single”)

i tried several ways but i couldnt find a solution.

could you help me fix my condition please? :slight_smile:

Hi.
To clarify. Paste a sample of your json array as text or in node view.

“childrenUnder21”: {“childrenDetails”: [{“numberId”: “111111”, “firstName”: “Tom”, “lastName”: “Tom”, “birthDay”: “05/05/2005”, “familyStatus”: “Single”},{“numberId”: “222222”, “firstName”: “Ben”, “lastName”: “Ben”, “birthDay”: “04/04/2004”, “familyStatus”: “Single”}]}

Lets assume a json as here:
grafik

we can access the birthday as a datetime like:
grafik

an initial filtering we can do like (status)


for the Year

but we dont have items for older then 21, so we showcase it for 17:

But kindly note: days / 365 will ignore the leap years, now.Year - Birthday.Year > 21 will ignore if the birthday is before now or later within the year.

With the help of the Query syntax we can do:

listMajors =

(From x In myJObject("childrenUnder21")("childrenDetails").Values(Of JObject)
Let dob = x("birthDay").Value(Of DateTime)
Let age = now.Year - dob.Year - Convert.ToInt32(now.Date < New DateTime (now.Year, dob.Month, dob.Day).Date)
Where x("familyStatus").toString.ToUpper.Equals("SINGLE") And age > 21
Select p=x).toList

hello,
first of all thank you for your help :slight_smile:
second, i got and error: “String was not recognized as a valid DateTime”

Can you share the value which is sent to conversion thanks