Sign in to follow this  
Followers 0
Janio Aguiar

Quantidade de meses entre Datas

3 posts in this topic

Função para retornar quantidade de meses entre duas datas.

Contribuição do nosso colega Rinaldo

PROCEDURE NumeroMeses(LOCAL dParametroDataInicial, LOCAL dParametroDataFinal)

dDataInicial is Date = dParametroDataInicial

dDataFinal is Date = dParametroDataFinal

nContador is int = 0

WHILE dDataInicial <> "" AND dDataInicial < dDataFinal

	dDataInicial..Month++

	nContador += iif(dDataInicial <= dDataFinal, 1, 0)

END

RESULT nContador

 

Share this post


Link to post
Share on other sites

PROCEDURE Iif(Condicao is boolean, Resultado_True, Resultado_False)
IF Condicao THEN
    RESULT Resultado_True
ELSE
    RESULT Resultado_False    
END

1 person likes this

Share this post


Link to post
Share on other sites

Pode ser assim também, sem usar a função IIF():

PROCEDURE NumeroMeses(LOCAL dDataInicial, LOCAL dDataFinal)
nContador is int = 0
WHILE dDataInicial <> "" AND dDataInicial < dDataFinal
    dDataInicial..Month++
    IF dDataInicial <= dDataFinal THEN
        nContador++
    END
END
RESULT nContador

3 people like this

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0