visual-basic-6 – How to get the following month and year in classic ASP?

Question:

For example, it's March 2015. I can get the next month of the current year using month()+1 concatenating with year() , that is, the month of April 2015. But let's say it's December 2015, How do I automatically get the month of January and the year 2016 ? Is there any function that does this without me having to compare the month?

Answer:

You can add or remove time intervals to a date with the DateAdd function, 3 it is necessary to inform 3 arguments: the interval, quantity and date.

available ranges

yyyy |  Ano
q    |  Quarto
m    |  Mês
y    |  Dia do ano
d    |  Dia
w    |  Dia da semana
ww   |  Semana
h    |  Hora
n    |  Minuto
s    |  Segundo

Example:

<% 
  data = "2015-01-01"
  response.write month(DateAdd("m", -1, data)) &" - "& year(DateAdd("m", -1, data))
  response.write month(DateAdd("m", 12, data)) &" - "& year(DateAdd("m", 12, data))
%>

Exit:

12 - 2014
1 -  2016
Scroll to Top