Problem with time formating

Hello,

i want to calculate the age of a person with:

$(countdown 9 26 1979 00:00:00 AM Europe/Berlin)

that is working, but if i try to format this. i always got error. i just want the year, so i thougt i usw:

$(countdown 9 26 2020 00:00:00 AM Europe/Berlin “YY”) but whatever i tryed, no formating works.

can pls someone help ?

As far as I know there is no way to format the countdown, but it may be possible with the use of an eval to check just the year. But it would be pretty complicated. I can try to work something out if you really want this.

Hey @sucooon!

To count from a date into the future, you should use $(countup) instead of $(countdown).
As explained in the documentation:
countdown: use the variable to create commands that display the time left until a specified date.
countup: use the variable to create commands that display the time since a specified date.

Now that this issue is out of the way, let’s see how to do what you’re looking for:

$(eval y=`$(countup 09 26 1979 00:00:00 AM Europe/Berlin)`.split(` `);y.length=2;y.join(` `);)

With this you’ll get XX years as a result.
If you wish to only have XX, replace y.length=2;y.join(` `); with y[0];, like this:

$(eval y=`$(countup 09 26 1979 00:00:00 AM Europe/Berlin)`.split(` `);y[0];)
1 Like

thx you for your help :slight_smile:

is it posible to set the date by the user like in this way?

$(eval const q = decodeURIComponent(`$(query)`).split(`.`); y=`$(countup ${q[1]} ${q[0]} ${q[2]} 00:00:00 AM Europe/Berlin)`.split(` `); `${y[0]} ${q[0]} ${q[1]}  ${q[2]} `; )

so the user can enter his bday like !bday 22.2.1979

If you replace $(query) with $(querystring) this seems correct.

$(eval const q = decodeURIComponent(`$(querystring)`).split(`.`); y=`$(countup ${q[1]} ${q[0]} ${q[2]} 00:00:00 AM Europe/Berlin)`.split(` `); `${y[0]} ${q[0]} ${q[1]}  ${q[2]} `; )

i try this too but also get invalid back

Okay, seems like $(countup) is capricious, I tried a lot of things to avoid using an alias, but we don’t have a choice.

Here are the commands to add from the chat:

!addcom !bday -a=_bday $(eval q=decodeURIComponent(`$(querystring)`).split(`.`); m=q.splice(1,1); q.unshift(m); q.join(` `);)
!addcom _bday $(eval q=`$(query)`.split(` `); d=q.splice(1,1); q.unshift(d); y=`$(countup $(query) 00:00:00 AM Europe/Berlin)`.split(` `); `${y[0]} - ${q.join(`.`)}`;)

ah thank you very much. so as far as i understand, its not posible to change the string in the $(countup) so a secound command is used to transform the insert query in a new query for a subcommand

Short answer is yes, long answer is a bit more complicated, it’s technically possible, but we can’t do too many manipulations or it breaks.

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