The other day I showed you how I wrapped the DateDiff function into my own function so that I wouldn’t have to remember that “n” is for minutes, among other things. Well the DateAdd function uses the same constants so it only makes sense to use a wrapper function here as well.
Function GetDateAdd(dtStart,iInterval,sInterval)
’ Valid interval values are:
’ Months,Days,Minutes,Hours,Seconds and they
’ are not case sensitive
Select Case LCase(sInterval)
Case “months”
result = DateAdd(“M”,iInterval,dtStart)
Case “days”
result = DateAdd(“d”,iInterval,dtStart)
Case “minutes”
result = DateAdd(“n”,iInterval,dtStart)
Case “hours”
result = DateAdd(“h”,iInterval,dtStart)
Case “seconds”
result = DateAdd(“s”,iInterval,dtStart)
Case Else result=”Unknown interval”
End Select
GetDateAdd=result
End Function
The form should look very similar to you if you read my last post. This function will return a calculated date time in the specified interval:
dtNow=Now
i=7
WScript.Echo “The date/time from ” & dtNow & ” in:”
WScript.Echo i & ” Months: ” & GetDateAdd(dtNow,i,”months”)
WScript.Echo i & ” Days: ” & GetDateAdd(dtNow,i,”days”)
WScript.Echo i & ” Hours: ” & GetDateAdd(dtNow,i,”hours”)
WScript.Echo i & ” Minutes: ” & GetDateAdd(dtNow,i,”minutes”)
WScript.Echo i & ” Seconds: ” & GetDateAdd(dtNow,i,”seconds”)
You can also use a negative number to calculate a past date/time value.
Again, I’ve attached a text file with the code so you don’t have to copy and paste.