0

How to trigger a change in date?

Hello

I posted a similar a few days ago that was unanswered so i'm posting a simplified version of it. 

I am trying to figure out the code to trigger a change in date by one year. For example, if it is today's date 10 June 2020, is there a trigger code that can change the date to 10 June 2021?

Thank you anyone who can help with this (or tell me if it's not possible!)

Ben

8 replies

null
    • Nick
    • 3 yrs ago
    • Reported - view

    Try this:

    ---

    let d := Date;
    Date := date(year(Date), month(Date) + number(12), day(Date))

    ---

    • Earthsong Seeds
    • Ben_Heron
    • 3 yrs ago
    • Reported - view

    It works! Thank you so much.

    I've added the code as a trigger in a button and it works perfectly. I was hoping i might be able to use the same code in 'update multiple records' but that doesn't seem to apply as a formula. This is where my understanding of the system (and the code itself) falls short. Can you think of a way i could apply the same outcome for multiple dates in a table? 

    • Nick
    • 3 yrs ago
    • Reported - view

    This code will loop through the records (try it in a test db first)

    ---

    for i in select 'Table Name' do
    let d := Date;
    i.(Date := date(year(Date), month(Date) + number(12), day(Date)))
    end

    ---

    • Earthsong Seeds
    • Ben_Heron
    • 3 yrs ago
    • Reported - view

    Hi Nick

    Thanks for for suggestion. Unfortunately i haven't been able to get this one to work - i get a message saying 'This formula may not modify data'. I've been adding this code to 'Update Multiple Records / Assign calculated value' - is that the correct place to put the code?

    • Nick
    • 3 yrs ago
    • Reported - view

    No, assign this code to a button in your form.

    • Earthsong Seeds
    • Ben_Heron
    • 3 yrs ago
    • Reported - view

    Yes - that works perfectly! Thank you again Nick - hugely appreciated.

    • zoranlicinar
    • 2 yrs ago
    • Reported - view

    Nick / Ben,

     

    Can you explain where / how you are entering this formula?

     

    I am wanting to create a column that adds +1 day to each existing date field.

     

    Thanks,
    Simon

    • Mel_Charles
    • 2 yrs ago
    • Reported - view

    Simon

    create a button

    then add the code to the 'on click' section

Content aside

  • 2 yrs agoLast active
  • 8Replies
  • 1100Views