# Filter for kids turning 12 years old this year? Javascript?

**URL:** <https://community.glideapps.com/t/filter-for-kids-turning-12-years-old-this-year-javascript/65617>\
**Category:** Ask for Help\
**Created:** [August 30, 2023, 7:40pm UTC](https://community.glideapps.com/t/filter-for-kids-turning-12-years-old-this-year-javascript/65617 "2023-08-30T19:40:47Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![Maksidaa](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/maksidaa/32/62648_2.png) [@Maksidaa](https://community.glideapps.com/u/Maksidaa)\
**Post date:** [August 30, 2023, 7:40pm UTC](https://community.glideapps.com/t/filter-for-kids-turning-12-years-old-this-year-javascript/65617/1 "2023-08-30T19:40:48Z")

</div>

I’m making a youth sports team app, and I need to be able to filter out all kids turning 12 this calendar year. I’ve tried a few different If-Then-Else parameters, but I’m struggling to filter those kids with birthdays mid year and early in the year.

For data I have birth dates, and I’m hoping to have a Javascript or If-Then-Else column to help me filter the kids. Any ideas?

---

<div class="post-metadata">

**Author:** ![Robert\_Petitto](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/robert_petitto/32/25193_2.png) [@Robert\_Petitto](https://community.glideapps.com/u/Robert_Petitto)\
**Post date:** [August 30, 2023, 7:46pm UTC](https://community.glideapps.com/t/filter-for-kids-turning-12-years-old-this-year-javascript/65617/2 "2023-08-30T19:46:21Z")

</div>

Just the ones turning 12 or those kids and younger?

---

<div class="post-metadata">

**Author:** ![Maksidaa](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/maksidaa/32/62648_2.png) [@Maksidaa](https://community.glideapps.com/u/Maksidaa)\
**Post date:** [August 30, 2023, 8:13pm UTC](https://community.glideapps.com/t/filter-for-kids-turning-12-years-old-this-year-javascript/65617/3 "2023-08-30T20:13:30Z")

</div>

Filter out kids turning 12 this year, show all kids that are less than 12 years old and NOT turning 12 this year

---

<div class="post-metadata">

**Author:** ![Robert\_Petitto](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/robert_petitto/32/25193_2.png) [@Robert\_Petitto](https://community.glideapps.com/u/Robert_Petitto)\
**Post date:** [August 30, 2023, 8:30pm UTC](https://community.glideapps.com/t/filter-for-kids-turning-12-years-old-this-year-javascript/65617/4 "2023-08-30T20:30:31Z")

</div>

Wouldn’t all 11-year-olds be turning 12 this year? So you want to show anyone who is (or younger than) 10 or just turned 11? Hide everyone who is older (12+)?

---

<div class="post-metadata">

**Author:** ![Maksidaa](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/maksidaa/32/62648_2.png) [@Maksidaa](https://community.glideapps.com/u/Maksidaa)\
**Post date:** [August 30, 2023, 8:47pm UTC](https://community.glideapps.com/t/filter-for-kids-turning-12-years-old-this-year-javascript/65617/5 "2023-08-30T20:47:23Z")

</div>

Something like that. For instance, if a kid turns 11 this year on January 1, then they will be 11 years old all year, but only turning 12 next year. So I can’t filter that kid out. So I can filter out anyone who is 12 years old, that’s the easy filter. I can keep anyone who is 10 years old or younger. But what do I do to filter the 11 year olds that turned 11 this year vs turned 11 last year and thus will turn 12 this year?

---

<div class="post-metadata">

**Author:** ![Maksidaa](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/maksidaa/32/62648_2.png) [@Maksidaa](https://community.glideapps.com/u/Maksidaa)\
**Post date:** [August 30, 2023, 9:09pm UTC](https://community.glideapps.com/t/filter-for-kids-turning-12-years-old-this-year-javascript/65617/7 "2023-08-30T21:09:27Z")

</div>

I asked ChatGPT for a Javascript solution and this is what it gave me (but I have no idea how to intergrate this into my Glide Sheet):

// Function to check if a birth date will result in turning 12 this year  
function willTurn12(birthdate) {  
const currentYear = new Date().getFullYear();  
const birthYear = birthdate.getFullYear();  
const age = currentYear - birthYear;

return age === 11; // Age 11 corresponds to turning 12 this year  
}

// Example birth date (replace this with the actual birth date you want to check)  
const exampleBirthdate = new Date(‘2011-03-15’);

// Check if the example birth date will result in turning 12 this year  
if (willTurn12(exampleBirthdate)) {  
console.log(‘The person with the given birth date will turn 12 this year.’);  
} else {  
console.log(‘The person with the given birth date will not turn 12 this year.’);  
}

---

<div class="post-metadata">

**Author:** ![Maksidaa](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/maksidaa/32/62648_2.png) [@Maksidaa](https://community.glideapps.com/u/Maksidaa)\
**Post date:** [August 30, 2023, 9:19pm UTC](https://community.glideapps.com/t/filter-for-kids-turning-12-years-old-this-year-javascript/65617/8 "2023-08-30T21:19:04Z")

</div>

> [@Maksidaa](#):
>
> {  
> const currentYear = new Date().getFullYear();  
> const birthYear = birthdate.getFullYear();  
> const age = currentYear - birthYear;
> 
> return age === 11; // Age 11 corresponds to turning 12 this year  
> }

So according to this, if I can find a way to produce the current calendar year then I can subtract the calendar year of the kids birth date. Then if I get 12, then filter out all those kids. So now I just need to figure out how to get a column that displays the calendar year

---

<div class="post-metadata">

**Author:** ![Maksidaa](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/maksidaa/32/62648_2.png) [@Maksidaa](https://community.glideapps.com/u/Maksidaa)\
**Post date:** [August 30, 2023, 9:27pm UTC](https://community.glideapps.com/t/filter-for-kids-turning-12-years-old-this-year-javascript/65617/9 "2023-08-30T21:27:22Z")

</div>

I think I figured it out.

Create math column with YEAR(N) where N is “now” and then another math column where Year(NOW)-Birth Date Year

Then if that value is greater than or equal to 12 then false

---

<div class="post-metadata">

**Author:** ![Robert\_Petitto](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/robert_petitto/32/25193_2.png) [@Robert\_Petitto](https://community.glideapps.com/u/Robert_Petitto)\
**Post date:** [August 30, 2023, 11:03pm UTC](https://community.glideapps.com/t/filter-for-kids-turning-12-years-old-this-year-javascript/65617/10 "2023-08-30T23:03:13Z")

</div>

That’s what I was going to propose. Glad you found it first!

---

<div class="post-metadata">

**Author:** ![system](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/system/32/53398_2.png) [@system](https://community.glideapps.com/u/system)\
**Post date:** [September 6, 2023, 11:03pm UTC](https://community.glideapps.com/t/filter-for-kids-turning-12-years-old-this-year-javascript/65617/11 "2023-09-06T23:03:41Z")

</div>

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