Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

check box based on date calculation 1

Status
Not open for further replies.

bledsoet

Technical User
Jan 23, 2002
3
US
Have an application were we are tracking a how long someone has been a member within our orginization. Would like to have an automated process where a check box is automatically selected when a specific date is reached.

ie., when someone has been a member for 5 years based on hire date, the check box for 5 years is automatically selected.
 
run this query
change tablename to your tablename
Fieldname to your Fieldname
Code:
update Tablename Set Fieldname = true
where Fieldname = False and DateDiff("yyyy", hiredate, now()) >=5
 
Warning: the DateDiff function may not always return the result you expect.
e.g. DateDiff("yyyy", #2006-12-31#, #2007-01-01#) = 1

So, a safer way:
UPDATE Tablename SET Fieldname = True
WHERE Fieldname = False AND hiredate <= DateAdd("yyyy", -5, Date())

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top