Posted By: Maelish
## Even/Odd Minute - 27/01/20 01:08 PM

How would I detect if a minute from `$time` was even or odd?

Also, how would I use just the last digit from minutes as well? Meaning you'd be able to use 0 - 9.

Thanks in advance!

You can get the last digit using something like

echo -a $right( $time(n), 1)

and to check if something is even, you check if its a multiple of 2

if (2 // $right( $time(n), 1)) {
echo -a even
}
else {
echo -a odd
}

References:

/help $right

/help $asctime

/help if-then-else

Posted By: Wims
## Re: Even/Odd Minute - 27/01/20 01:56 PM

Use $time(n) to get the number of minute and you can use $iif(N & 1,1,0) to know if a number is odd or not

Posted By: maroon
## Re: Even/Odd Minute - 27/01/20 02:40 PM

You would first floor-divide the ctime (number of seconds since year 1970) by 60 to obtain the number of minutes. Then you would get the modulo remainder from dividing that by 2, where 1 would indicate an odd number and 0 would indicate even. If you want it the other way around, use (1-result) instead of (result).

//echo -a $calc( ($ctime // 60) % 2) => $asctime

And for the last digit, since you're asking for a range size of 10 instead of odd-vs-even, the modulo would be 10 instead of 2

//echo -a $calc( ($ctime // 60) % 10) => $asctime

Posted By: Maelish
## Re: Even/Odd Minute - 27/01/20 04:12 PM

Ah, gotcha!

This either returns 0 (even) or 1 (odd).

//echo -a $calc( ($ctime // 60) % 2) => $asctime

And this gives you the last digit for minute.

//echo -a $calc( ($ctime // 60) % 10) => $asctime

Thanks @maroon!