I'm working on a program that generates trigger dates from a date of hire using the DateAdd function. I can do it in an Access form but I need to use Visual Basic, which I'm not very familar with. Can anyone help?
Printable View
I'm working on a program that generates trigger dates from a date of hire using the DateAdd function. I can do it in an Access form but I need to use Visual Basic, which I'm not very familar with. Can anyone help?
MSDN :
Quote:
DateAdd(interval, number, date)
The interval argument has these settings:
Setting Description
yyyy = Year
q = Quarter
m = Month
y = Day of year
d = Day
w = Weekday
ww = Week
h = Hour
n = Minute
s = Second
Great, but how would put that in a subroutine?
Code:Dim dt1 As Date, dt2 As Date
Dim dtNew As Date
Dim lDif As Long
'set two date objects
dt1 = "04/08/1979"
dt2 = Now
'find the number of months difference between the dates
lDif = DateDiff("m", dt1, dt2)
'add the difference to dt2, to create a new date
dtNew = DateAdd("m", lDif, dt2)
That helps, but I'm still having trouble getting the hire date from the database. Could someone show me an example?