0

Change colour of a formula box if it’s a year later

I have a Last Updated date box and a formula box called Last updated status, I basically want to make it so after a year from the date in the last updated box the formula for the status turns red.

TIA

10replies
{{batchActionsCtrl.state.selectedCount}} {{batchActionsCtrl.state.selectedCount==1?'reply':'replies'}} selected Move Cancel
Oldest first
  • Oldest first
  • Newest first
  • Active threads
  • Popular
    • Nick
    • Nick
    • 7 mths ago
    • Reported - view

    Try this in the formula box called Last updated status:

     

    let t := days('Last Updated', today());
    styled("Status", if t > 365 then "red" end)

    Reply Like
    • yewani
    • yewani
    • 7 mths ago
    • Reported - view

    It shows up as status in the box, but it doesn't change colour when more than 365 days

    Reply Like
    • yewani
    • yewani
    • 7 mths ago
    • Reported - view

    Nevermind it's sorted! Nice one Nick :)

    Reply Like
    • yewani
    • yewani
    • 7 mths ago
    • Reported - view

    Als what would I add to it to make it green when it is under 365 days? I've just tried with the same sort of code but it's not working for me.

    TIA

    Reply Like
    • Nick
    • Nick
    • 7 mths ago
    • Reported - view

    Sure,

    ---

    let t := days('Last Updated', today());
    if t > 365 then
    styled("Expired", "red")
    else
    if t < 365 then
    styled("Not Expired", "green")
    end
    end

    ---

    Change the words "Expired" and "Not Expired" to suit your needs

    Reply Like
    • John Halls
    • John_Halls
    • 7 mths ago
    • Reported - view

    Hi Nick

     

    I hope you don't mind but I would just have

     

    let t := days('Last Updated', today());
    if t > 365 then
    styled("Expired", "red")
    else
    styled("Not Expired", "green")
    end

     

    Regards John

    Reply Like
    • yewani
    • yewani
    • 7 mths ago
    • Reported - view

    Thank you both :)

    Reply Like
    • Nick
    • Nick
    • 7 mths ago
    • Reported - view

    You're right John, I just wanted to show him the case of multiple ifs...

    Reply Like
  • John/Nick

    Both methods work and that is good what you have shown yewani is that there are several ways to achieve the required result - even better !!
    In fact, a somewhat wise tutor once told me that when starting out with coding that was better to code it as you are saying it and have the multiple if's etc as it makes it initially easier to follow in your head. Once comfortable with what you are doing then you can go back and refine the code. I think he referred to it as spaghetti code back then cos we often resorted to jumping all over the place! Certainly made for some long coded scripts! before we embarked on proper sub routines etc. :-)

    Reply Like
  • That's beautifully put, as ever Mel 👍

    Reply Like
  • Spam
    • Remove post
    • Remove and block user
  • Edit
  • Publish
  • Unschedule
  • Cancel event
  • Uncancel event
  • Set status
    • Clear status
  • Pin
  • Unpin
  • Open replies
  • Close replies
  • Clear flags
  • Move
    • Move to category:
    • Learn & Share
    • Get help
  • Copy
    • Copy to category:
    • Current category
    • Learn & Share
    • Get help
  • Change type
    • Change topic type to:
    • Discussion
    • Question
    • Idea
    • Issue
    • Article
    • Event
  • Restore post
    • Spam
    • Offensive
    • Inappropriate
    • Duplicate
    • Other
  • Remove post
    • Spam
    • Offensive
    • Inappropriate
    • Duplicate
    • Other
  • Publish
  • Spam
    • Remove post
    • Remove and block user
  • Edit
  • Pin
  • Unpin
  • Open replies
  • Close replies
  • Label
    • Clear label
  • Move
  • Clear flags
  • Restore post
    • Spam
    • Offensive
    • Inappropriate
    • Duplicate
    • Other
  • Remove
    • Spam
    • Offensive
    • Inappropriate
    • Duplicate
    • Other
Like Follow
  • 7 mths agoLast active
  • 10Replies
  • 462Views