Usina BRAdvPL Guide
Sign in
← All topics
FUNCTIONPublished

AddMonth

AddMonth( <dData>, <nMeses> ) --> dData

Adds or subtracts months from a date while keeping the date type.

DateChronologicalDate arithmeticEssential functions
01 · OVERVIEW

Overview

AddMonth() is useful when a business rule works with due dates, projections, installments or validity periods measured in months. Instead of adding a fixed number of days, it moves the date by the informed number of months.

02 · SYNTAX

Syntax

AddMonth( <dData>, <nMeses> ) --> dData

Parameters

dData
DataRequired

Base date used in the calculation.

nMeses
NuméricoRequired

Number of months to add. Use a negative value to go back.

03 · PRACTICAL EXAMPLE

Calcular vencimento em três meses

#Include "TOTVS.ch"

User Function ExAddMonth()
    Local dDueDate := AddMonth(Date(), 3)

    MsgInfo("Due date: " + DToC(dDueDate))
Return
Expected result

Shows the current date plus three months.

BEST PRACTICES
  • Use AddMonth() quando a regra fala em meses, não em dias.
  • Para vencimentos comerciais, valide também feriados e dias úteis conforme a política da empresa.
  • Combine com DToS(), DToC() ou SToD() quando precisar gravar, exibir ou reconstruir datas.
COMMON PITFALLS
  • Datas próximas ao fim do mês podem exigir validação da regra de negócio quando o mês de destino tiver menos dias.
  • Não substitua regras de calendário financeiro por uma soma simples de 30 dias.

Related content

REFERENCES
  1. RXM Tecnologia. 20 essential AdvPL functions every Protheus developer uses. May 2026.
Status
Published
Page created on
Last reviewed on
Original language
Portuguese
Reviewed by
Usina.BR
0 approved comment(s)

Comments

There are no approved comments yet.

Sign in with Google or Microsoft to comment.

Powered by Usina Docs · Alpha