Not signed in (Sign In)

Vanilla 1.1.5a is a product of Lussumo. More Information: Documentation, Community Support.

  1.  
    I have a user enter date on a form.

    I want to calculate the number of months (rounded) between this date and 6/30/this year and also the number of months between this date and 12/31/this year.

    I want to use one or the other of these results in a calculated field.

    Questions:

    What is the formula to create 6/30/this year and/or 12/31/this year?
    What is the formula to calculate the number of months between two dates?

    I found some info, but the following is not working...
    Math.floor((Jun-MemEndDate)/(1000*60*60*24*365.25))
    (Jun = a hidden field with a default value of 6/30/2011, MemEndDate is a user entered date)

    Thanks
    • CommentAuthordbuschho
    • CommentTimeJan 31st 2011
     
    Hello,

    The reason the above isn't working is that your dates are being handled by javascript as strings. You'll need to write a custom function as shown here:
    http://www3.formassembly.com/forum/discussion/631/calculations-with-dates/#Comment_1959

    so something like:
    Math.floor((new Date(Jun)-(new Date(MemEndDate)))/(1000*60*60*24))
    would give you the difference in days.

    If you wanted the difference in banker months ( 30 uniform days ) you could divide by thirty above.

    If you want to actually diff the number of the months ( though I'm not sure how useful that would be ... as in 05/01/2010 - 04/30/2010 would equal 1 month difference ... obvious non-sense ):
    Math.floor((new Date("6/30/2011").getMonth() -(new Date("7/20/2011").getMonth())))