Birthday banner ±4 days

Hi All, I’ve done this a couple of ways but neither feel like they’re very efficient. Maybe some folks would enjoy showing me how stupid I am!!

I have users and have recorded their birthdays. I’d like to show them a happy birthday note on the welcome screen through the week of their birthday (as they may not log in on their exact birth date).

So…
Identify that its a date thats between 4 days prior and 4 days post birth date
Assume I’m recording their birthday as e.g. 01/01/1992

Thank you. Low priority so just wondering how other people would do it. Has to be better ways than I’m currently trying it.

This is an experimental reply from a bot. Please like it if it’s correct.

You can use the Date Range action to identify if the current date is between 4 days prior and 4 days post the user’s birthday. You can set the start date to the user’s birthday minus 4 days and the end date to the user’s birthday plus 4 days. This will return true if the current date is within the range. Learn more about the Date Range action here. Glide • Sheets FAQ

1 Like

JavaScript to the rescue:

let today = new Date();
let birthday = new Date(p1);
let birthday_this_year = new Date(today.getFullYear(), birthday.getMonth(), birthday.getDate());
let diff = Math.abs(today.getTime() - birthday_this_year.getTime());
let diff_days = Math.ceil(diff / (1000 * 3600 * 24));
return diff_days < 4 ? true : false;

1 Like

Here’s how I would do it.

The data

In the Users table, I would add the following 6 columns:

  • Today: basic math, now
  • TodayNoYear: basic math, MMDD
  • Birthday: basic DateTime, probably written to via a date picker
  • BirthdayNoYear: basic math, MMDD
  • BirthdayNoYear-4d: basic math, subtract 4 days
  • BirthdayNoYear+4d: basic math, add 4 days

The filter

The filter can be set either in the data editor in the Users table in an if-then-else column, or directly in the layout editor in the visibility options of the hint text.

In the layout editor in the visibility options:

In the data editor with an if-then-else column:

NB. In the data editor, other than the basic Birthday column, I would probably group all the computed columns under something like BirthdayBanner/ to keep the Users table organized.

1 Like

Impressive

Yep. Thats a lot better than my effort!

Thanks as always Darren. Much appreciated.

Nice. This is very close to how was doing it. @Darren_Murphy has kinda blown it out of the water with some tidy Javascript (I’m not at all Javascript fluent).

Interesting to see how people solve it though. I nearly always get where I need to be but I often look back and think there must be better ways of doing things. Especially as the app grows. I start wondering when I’ll see the impact of my sloppy solutions!

In the past I would have done something very similar to the option that @nathanaelb offered up.
And I generally try to avoid JavaScript where possible. But sometimes it’s too tempting, especially when you can save so many columns :wink:

3 Likes

I have not been hit by the Thinh phenomenon yet :slight_smile:

@KenApp
Darren’s javascript is beautiful. I can vaguely read and tinker javascript, but I cannot write it, so js is out of scope for me. I still stick to the onion method of having multiple columns in the data editor.

With Darren’s javascript, the true/false value to filter on is in the data editor directly. I edited my post above should you want to do the same with an if-then-else column.

3 Likes

Honored to be named haha.

1 Like

The Thinh phenomena is the process whereby a nocoder slowly but gradually becomes a coder. He continues to nocode and in parallel becomes comfortable in HTML, CSS, and JavaScript. Further, C++ and Scala are around the corner.

3 Likes

On the road map, dare I say :laughing:

2 Likes

I know another guy that’s been inflicted with that bug :wink:

3 Likes

Meanwhile, here I am using Glide so I can do less coding…

2 Likes

We’re all converging :rofl:

2 Likes

Probably not what Glide meant when they said a billion new “developers”…

I see they changed their mission statement to “creaters” instead.

3 Likes