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

Adding months or years to a DATE variable 1

Status
Not open for further replies.

chpicker

Programmer
Apr 10, 2001
1,316
Awhile back I saw someone asking about this, and I've spent over an hour trying to find the post again with no luck.

FoxPro has a function that will add a given number of months or years to a DATE variable. So, for example, if you take this:
Code:
ldMyDate=date()
?ldMyDate
?MonthAdd(ldMyDate,5)
The output would look like this:
Code:
11/16/2001
4/16/2002
Now, MonthAdd is for illustration only. FoxPro has a built-in function to do this. What is that function? I can't find it anymore!
 

? Gomonth(date_variable,numbwer_of_months)

* Example: to add 1 month to today's date
? gomonth(date(),1)
* Example: to add 1 year to today's date
? gomonth(date(),1*12)
* Example: to add 5 years to today's date
? gomonth(date(),5*12)
Etc...

 
Hi
Oh, there was somebody faster than I am:
Anyway - you can of course subtract with the gomonth-function:

Try this:

ldMyDate=date()
?ldMyDate
?gomonth(ldMyDate,-5)

*date() will be reduced by 5 month (from now November back June 2001)

Regards
Klaus
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top