+ 1

What's a real life use case for modulus?

29th Aug 2016, 12:55 AM
Scott Noroozi
Scott Noroozi - avatar
4 Answers
+ 3
@Scott Noroozi # say Sunday is day zero, Monday is day one, etc $what_day = $today % 7; # if $today is 7, then 7 % 7 = 0 so it's a Sunday. # if $today is 8, then 8 % 7 = 1 so it's a Monday.
3rd Sep 2016, 2:12 AM
DevCoder (John Sullivan)
DevCoder (John Sullivan) - avatar
+ 1
If today is Monday then 7 days from now it is Monday again.....and so on. This mod 7
30th Aug 2016, 2:18 AM
David Rodriguez
0
@David Rodriguez thanks man. so how would you write that if you don't mind sharing?
30th Aug 2016, 2:33 AM
Scott Noroozi
Scott Noroozi - avatar
0
what if today 2?
26th Sep 2016, 5:44 PM
Bumbarash2
Bumbarash2 - avatar