ASP DateAdd Function

Homepage > ASP Tutorials > ASP DateAdd Function

Sometimes you might need to add or subtract time from a date, for example if you're creating financial reports for the previous month, or year. This is where the DateAdd function comes in handy.

<%
  sDate = Now()
  sNewDate = DateAdd("m", 1, sDate)
  sMonthNext = Monthname(Month(sNewDate))
%>

This code takes the current date and adds one month to it. Once we've added a month, we then format the date to get the name of next month.

Here is a list of the different intervals you can use with the DateAdd function:

s - Second
n - Minute
h - Hour
d - Day
y - Day of year
w - Weekday
ww - Week of year
m - Month
q - Quarter
yyyy - Year

Related links

Rate this tutorial!

  • Currently 2.8/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Rated 2.8/5 stars (1285 votes cast)

Make an enquiry

Privacy policy