interval
numberof
Print DateAdd(7,"mm","01-01-1970 00:00:00")
InvoiceDue$=DateAdd(30,"d",Now())
Print DateAdd(-85000,"m","28-02-2010 17:00:00")
DSTTime$=DateAdd(60,"m",Now())
Function DateAdd(Num As Integer,Interval As String,dt As String) As String 'return a string of the datetime with the relevant period added 'add -ve to subtract e.g. 'DateAdd (2,"mm",Now()) returns the datetime time two months from now. 'DateAdd(-1000,"dd",Now()) returns the datetime a thousand days ago Local Integer x,y,z Select Case LCase$(Interval) Case "s"' Seconds DateAdd=HumanTime(UnixTime(dt)+Num) Case "m"' Minutes DateAdd=HumanTime(UnixTime(dt)+(Num*60)) Case "h"' Hours DateAdd=HumanTime(UnixTime(dt)+(Num*3600)) Case "dd" 'Days DateAdd=HumanTime(UnixTime(dt+(Num*86400)) Case "w" 'Weeks DateAdd=HumanTime(UnixTime(dt)+(Num*604800)) Case "mm"' calendar Months x=Val(Mid$(dt,4,2))-1: y=Val(Mid$(dt,7,4)): z=Val(Left$(dt,2)) x=((x+Num) Mod 12)+1: y=y+Num\12 If (x=2 And z=29) And (Not IsLeapYear(y)) Then ' bludgeon for 29/02 in non-leap year x=3:z=1 EndIf DateAdd=ZPad$(z,2)+"-"+ZPad$(Abs(x),2)+"-"+Zpad$(y,4)+ Right$(dt$,9) Case "yyyy"' Years x=Val(Left$(dt,2)): y=Val(Mid$(dt,4,2)): z=Val(Mid$(dt,7,4)): z=z+num If (y=2 And x=29) And (Not IsLeapYear(z)) Then ' bludgeon for 29/02 in non-leap year y=3:x=1 EndIf DateAdd=ZPad$(x,2)+"-"+ZPad$(Abs(y),2)+"-"+Zpad$(z,4)+ Right$(dt$,9) Case Else DateAdd="" End Select End Function