How to calculate the number days until someone's next birthday

How can I calculate the number of days between a user’s next birthday?

Let’s say the DOB is 1st January 2000 and the user is submitting this form today (22nd July 2024), how can I display the number of days remaining until their next birthday?

You could try something like:

user’s DOB:change years to current date/time: rounded down to year > current date/time:format as text

Formatting for yes:

((user’s DOB:change years to current date/time:rounded down to year) - current date/time): format as days

Formatting for no:

((user’s DOB:change years to current date/time:+year 1:rounded down to year) - current date/time): format as days

Keep in mind I haven’t tried this and it’s just off the top of my head. It should look something like this though the order of rounded down to year and + years might be different. Hope this helps

1 Like

You can add a minus between two dates to get the millisecond diff between them, which you then choose to format as day/month etc.

Date - date:format as days

will get you the exact number.

Hey Harry,

Thanks for your reply, I think I have applied the expression correctly but it’s prompting these errors.

I tried to troubleshoot this but tbh I didn’t know what I was doing in the first and just blindly applied your expressions.

Hey Ed,

Thank you, but it just returns the number of days/yeara between the user’s D.O.B. and the Current Date/Time

Hi, try replacing change years to current date/time:rounded down to year with

change years to current date/time:extract year

Keep everything else including the rest of the expression the same. Let me know if this works!

1 Like

This is to calculate an age, but illustrates some of the techniques mentioned by others for your need.

1 Like

This is a lot of unnecessary expressions.

Use a plugin or a JS library called moment.js.

Enter the date you want to calculate the time to, and it does the work for you.

It’ll output “… days until”, “… seconds until”, “… minutes until”.

3 Likes

Apologies, I didn’t fully read this last night and assumed you’d have the future bday to draw from.

It sounds like @harry7 had the right idea since you need to programatically calculate the future birthday, I don’t think anything above works without that happening first (unless the JS library has a richer feature to handle this use case, which it may).

Here’s how it looks:

1 Like

This topic was automatically closed after 70 days. New replies are no longer allowed.