Calculating a date and formatting as a date

Comments

8 comments

  • Rainer Grabowski (FVM)

    Hi Craig,

    moment(@Site Start).subtract('days', 28).toDate()
    

    returns it in date format.

    Rainer

    0
    Comment actions Permalink
  • Rainer Grabowski (FVM)

    NB: Create a new calculation field for it, cause your existing field in now a text type calculation field and you can't change that.

    0
    Comment actions Permalink
  • Craig Strachan

    Hi Rainer

    That's brilliant thank you, I'll give that a go now...

    Thanks again

    0
    Comment actions Permalink
  • Amber Wells
    I'm having problems with the following:
    moment(@Min of Event Date).subtract('days', @LeadTime).toDate()

    @Min of Event Date is a static start date (date field)
    @Lead time is variable for each action item (text field as whole number)

    Formula is generating the same result for all action items, regardless of variable lead times: 12/31/1969 6:00 PM

    Any idea what is causing the error?

    Thanks!
    0
    Comment actions Permalink
  • Rainer Grabowski

    Hi Amber,

    cause @LeadTime is a text field the number in there is in text format (= a string) , but in that formula it must be in number format. You've to parse it to number format first. 

    var lt = Number(@LeadTime) || 0;
    moment(@Min of Event Date).subtract(lt,'days').toDate()

    Rainer

    0
    Comment actions Permalink
  • Gus H.

    Hi Rainer. Can we do the opposite? Instead of subtracting can we add one day? On the code: moment(moment().format('YYYY') + '-' + moment(@Birthday).format('MM-DD')).toDate(); we get the anniversary date one day before the exact date, i.e. +365. How can we add one more day so the code returns the exact anniversary date? 22nd to 22nd, and not 22nd to 21st of March, as an example. Thanks as always.

    0
    Comment actions Permalink
  • Rainer Grabowski

    Hi Gus,

    Q: Can we do the opposite?

    A: Yes, just do the opposite: .add(1,"day").toDate().

    But I don't understand your code: moment(moment().format('YYYY') + '-' + moment(@Birthday).format('MM-DD')).toDate()

    It shows you the date for the year you enter something in the field @birthday. But the year value will never change, it will always show 2017 (except you will change something directly in the calculation). moment() catches the moment you do something.
    And what about leap years? You have to add 2 days.

    If your want to have a date field which always shows the next anniversary date you need another setup.

    Rainer

    0
    Comment actions Permalink
  • Stuart Kibbe

    Hi Rainier, hi All, 

    Thought I would piggy-back off this post as you made a relevant comment to my scenario. 

    I have an "agreements" app which holds all my agreements, either supplier or partner agreements. 
    In the app, I have a start date, (Date field) and a contract duration (number field). 
    I also have a calculation field which I would like to calculate the upcoming renewal date of the contract.

    So for example, if I have a contract starting 1.11.2017 with a duration of 12 months, I would like to calculation to return 1.11 so that each year the contract is active, I will see the date it is due.  

    2 questions:

    1. How would I calculate the "due date" ie the day and month that a contract is up for renewal, given the data above? 
    2. How would I automatically create a task (for example 14 days before a contract is up) to renew, and an email alerting me of the deadline?

    Any help would be much appreciated!
    Stuart

    0
    Comment actions Permalink

Please sign in to leave a comment.

Powered by Zendesk