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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Date calculation - adding years 1

Status
Not open for further replies.

puppygirl3939

Technical User
Sep 15, 2003
21
0
0
US
Hello!

This seems rater simple but I have tried my best to accomplish this to no avail. I would like to be able to add two years to a date. Example I have a Date Requested field which the user will enter and I want to automatically have the system complete the Expiration Date field based on the Requested Date field. If the requested date is 7.15.2005 the expiration date should be automatically populated with 7.15.2007.

Any ideas!
 
Would

dExpDate = GOMONTH(dReqDate,24)

work for you?

Regards,
Jim
 

You can also use Date() function.

RequestedDate={7/15/2005}
rYear=YEAR(RequestedDate)
rMonth=MONTH(RequestedDate)
rDay=DAY(RequestedDate)
addYears=2
ExpirationDate=DATE(rYear+addYears, rMonth, rDay)

You will have to add code to avoid Feb.29 issue.
 
Wow!!!!

One line of code in the LostFocusEvent and it worked. You guys are my heroes.!!!!
 
Perhaps I missed something here but the first solution that came to mind for me was the dateadd function. For my own knowledge is there a reason why the following code wouldn't work? This also seems to work for the Feb 29 issue.

[txtDate] = Any date you choose
[txtDateExpired] control source =DateAdd("yyyy",2,[TxtDate])
 
03SCBeast,

The reason DateAdd() won't work is that this is a forum for Visual FoxPro. I grant you that DateAdd() works really well in VB, VBA, and VBScript, though.

boyd.gif

SweetPotato Software Website
My Blog
 
Thanks Craig...as always, I knew I would learn something new.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top