Calendar one month to go! help

kjflukekjfluke Member, PRO Posts: 23
Hi. I have a really lame problem. I have been looking through the forums for an answer that I can use and can't quite get there, so I apologize if this is a frequently asked question. I have an app that displays different text for each day of the year, called from a table. What I am trying to do is have it recognize when todays date is one month before a certain date. Or one week before. The year is irrelevant. I tried using a subtraction method like this:

(game.Clock.Month+11)%12

which works well but I can't remember how to make it skip 0. Any quick help would be greatly appreciated.
-K

Best Answer

  • RThurmanRThurman Posts: 2,881
    Accepted Answer
    What you are doing is correct. (I was just answering how you skip "0" in a sequence. I was not answering how to determine what the next month is.)

Answers

  • kjflukekjfluke Member, PRO Posts: 23
    Ok. I found the skip zero on another thread answered by T-shirt Booth.
    (game.Clock.Month+11)%12+1
    sounds like it should work. Thanks T-shirt Booth.
  • RThurmanRThurman Member, Sous Chef, PRO Posts: 2,881
    The general formula to skip "0" looks like this:

    ((a-1)%b)+1

    For months of the year it would look something like:
    (game.Clock.Month-1)%12+1

    Here month 12 would be "12" and month 13 would be "1"
  • kjflukekjfluke Member, PRO Posts: 23
    Thanks RThurman. For some reason I can't get the formula to work that way. It keeps coming out with the month it is starting with. For example, If I had a certain date set to Feb 9, one month from today, I use (february-1)%12+1, or in other words, (2-1)+1, which is 2. To get one month less than the event date I had to use this:
    (game.EventMonth-2)%12+1. That seems to have worked, though I don't know why the other didn't work.
  • kjflukekjfluke Member, PRO Posts: 23
    Thanks!
Sign In or Register to comment.