Date/Time - Checking age verification prior to 1/1/1970?

Options

When converting a date/time to a unix time stamp, how can I check if a user is older than 18yo, 21yo, 59 1/2, and 72 years old?

If the user is older than Jan 1, 1970, the negative number is _less than_ 72 years.

Seventy-two years in seconds is 2,264,371,200.

Seventy-two years in epoch/unix time is -631,152,000 (negative value).

Twenty-one years in seconds is 660,441,600.

Twenty-one years in epoch/unix time is 978,307,200 (positive value).

How would you do the math for a True/False result to check for = > 72 years?

How would you do the math for a True/False result to check for = > 21 years?

Subtracting from now with a negative number just gets me closer to 1970, but not the full time scale of negative value prior to 1970.

Do I need to run a conditional that if my epoch date is negative, then add(?) the seconds between 01/01/1970 and now?

Any help appreciated.

Comments

  • Ed Martin
    Ed Martin Member
    Options

    Wrapping my head around the challenge -

    Epoch Now is 1,667,104,230 (at the time of this post)

    72 years in Epoch is -605,038,046 (at the time of this post)

    72 years in seconds is 2,272,142,276 (close enough ;-))


    If Epoch Now is 1,667,104,230 + 72 years epoch -605,038,046 = 2,272,142,276 seconds

    Then Epoch Now 1,667,104,230 - 2,272,142,276 = Epoch Date of age 72 -605,038,046

    If current age is greater than -605,038,046 epoch seconds then age = > 72 is True


    Does this look like the correct breakdown, thinking, path, direction?

    Now (how) to get this into a function ?!?!?

  • Ray Deck
    Ray Deck Trusted Xano Expert ✭✭✭
    Options

    The thinking seems ok. I believe you're really comparing birthdays rather than ages directly. The birthday of someone 72 years old today would be 10/30/1950, which is 19 years before 1/1/1970, and so the epoch time value of that timestamp is a negative number.

    All that said, the "modify_timestamp" filter is a way to play on easy. If you have birthday as timestamp X, you could test whether X < (const:now filter:modify_timestamp value: "-72 years").

  • Michael Udinski
    Michael Udinski Administrator

    ADMIN

    edited November 2022
    Options

    Hey @Ed Martin a simple birthday calculation should suffice for people born before or after the beginning of UNIX time. Here's a quick example:


    Snippet:

    https://www.xano.com/snippet/6P6nbGfn