Snippet help - calculate number of days in month from date

Here is my full snippet finally working.

Thanks @Gaurang_Tandon for helping me streamline some of the issues that were bugging me!!!

Some of the logic:

  • Calculate pro-rated rent for remaining days in the month
    -- If the move-in date is >= 25th then calculate including next month's rent as well
  • Calculate pro-rated pet rent into proration
  • Calculate pet deposit based on number of pets and include in move-in funds
  • Subtract pro-rated rent of $400 from reservation binder fee of $550
  • Calculate monthly rent + pet rent based on number of pets
  • Calculate total move in costs including security deposit and pet fees and pro-rated rent and reservation binder fee
  • Calculate remaining balance after reservation binder fee has been paid

{note}
FILL IN FIELDS TO CALCULATE
Monthly rent: ${formtext: name=mr; default=; cols=10}
Move-in Date: {formdate: YYYY-MM-DD; name=moveindate}
Pets:{formmenu: default=0; 1; 2; 3; name=petnum; cols=5}
Concession: {formmenu: default=None; First full month of rent free; $500 off first full month of rent; $500 first responder/military discount; name=concession}
{endnote: trim=right}

ESTIMATED MOVE IN FUNDS*
Reservation binder fee: $550
$400 goes towards pro-rate, $150 admin fee
Security deposit (one month's rent): ${formtext: name=mr; default=}
Pro-rated rent from {frommid={time: M/D/YYYY; at={=moveindate}; pattern=YYYY-MM-DD}}{=frommid} until {if: mid <= 24}{=getlastdate(nextmonthstart)} {else} {=getlastdate(nextnextmonthstart)}{endif}: {if: mid < 25}{=(mr/dim)(dim-mid+1) +(petnum * 35 / dim) * (dim - mid +1) - 400; format=$,.2f}{else}{=(mr/dim)(dim-mid+1) +(petnum * 35 / dim) * (dim - mid +1) + mr + (petnum *35) - 400; format=$,.2f}{endif}

  • minus $400 from reservation binder
    {if: mid >= 25} * including following month's rent if move-in is the 25th or after{endif}
    {if: petnum > 0} * including pet rent for {formtext: name=petnum} pet(s) {endif}
    {if: petnum >= 1}Non-refundable pet fee: {if: petnum == 0}n/a{elseif: petnum == 1; trim=yes}$250.00{elseif: petnum == 2; trim=yes} $350.00
  • $250 first pet, $100 second pet{elseif: petnum == 3; trim=yes}$450.00
  • $250 first pet, $100 for second and third pet{endif} {endif}
    Total due after reservation binder fee (minus $550): {if: mid < 25}{=(mr/dim)(dim-mid+1) +(petnum * 35 / dim) * (dim - mid +1) + x + mr - 400; format=$,.2f}{else}{=(mr/dim)(dim-mid+1) +(petnum * 35 / dim) * (dim - mid +1) + (mr2) + (petnum 35) + x - 400; format=$,.2f}{endif}
    All in total including reservation binder fee (plus $550): {if: mid <= 24}{=(mr/dim)
    (dim-mid+1) +(petnum * 35 / dim) * (dim - mid +1) + x + mr + 550 - 400; format=$,.2f}{else}{=(mr
    2)+(mr/dim)*(dim-mid+1) +(petnum * 35 / dim) * (dim - mid +1) + (petnum *35) + x + 550 - 400; format=$,.2f}{endif}

Other details
Monthly rent: ${=mr + (petnum * 35)} {if: petnum > 0}(includes rent for {=petnum} pets at {=petnum * 35; format=$,.2f}/per month){endif}
Move-in concession: {=concession}

  • Please note that this is just an estimate. Please always refer to your reservation binder email for actual amounts.

{mid={time: DD; at={=moveindate}; pattern=YYYY-MM-DD}}
{dim=datetimediff(startmonth, nextmonth, "D")}
{nextmonth={time: YYYY-MM-01; at={=moveindate}; pattern=YYYY-MM-DD; shift=+1M}}
{startmonth={time: YYYY-MM-01; at={=moveindate}; pattern=YYYY-MM-DD}}
{leftdaysmonth=datetimediff(moveindate, nextmonth, "D")}
{getstartdate=(shift)->{time: YYYY-MM-01; at={=moveindate}; pattern=YYYY-MM-DD; shift=+{=shift}M}; trim=right}
{getlastdate=(firstdate)->{time: MM/DD/YYYY; at={=firstdate}; pattern=YYYY-MM-DD; shift=-1D}; trim=yes}
{nextmonthstart=getstartdate(1)}
{nextnextmonthstart=getstartdate(2)}
{if: petnum == 0}{x=0}{endif}
{if: petnum == 1}{x=250}{endif}
{if: petnum == 2}{x=350}{endif}
{if: petnum == 3}{x=450}{endif}

3 Likes