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

What is FoxPro's version of DateAdd?

Status
Not open for further replies.

majorbroncosfan

Programmer
Feb 23, 2001
121
US
In Visual Basic and MS Access, I am able to use the DateAdd function to add one year to a date. What is the equivalent function in Visual FoxPro? Does somebody have an example?
 
Actually, FoxPro is even easier than either of those when it comes to adding dates. However, adding an exact year would be a little more complex. Here's the basics:

To go forward or backward a number of days, simply add the number. Example:
Code:
ldToday = DATE()
ldTomorrow = ldToday+1
Pretty easy, huh? That will simply go forward or backward a single day, wrapping to the next/previous month and year if necessary. To add a month or a year, though, gets a little bit more complex...you'll need to split the date into the 3 fields. So, to add a year, do this:
Code:
ldToday=DATE()
lnDay = DAY(ldToday)
lnMonth = MONTH(ldToday)
lnYear = YEAR(ldToday)
lnYear=lnYear+1
lcNewdate=ALLTRIM(STR(lnDay))+"/"+ALLTRIM(STR(lnMonth))+"/"+ALLTRIM(STR(lnYear))
ldNextYear=CTOD(lcNewdate)
Not really simple, but the above code should allow you to take a date field and add a year to it. Be sure to change the order of the lcNewdate assignment if your regional settings for date format aren't DD/MM/YYYY.
 
Well, I'm using Visual Basic and SQL Server to achieve these results, as the program I am trying to change uses FoxPro as their back-end, but only through .DBF files. There is a completely separate front-end. Is there any way to do this via Visual Basic?
 
To add 1 year to a date use the GOMONTH() function - add 12 months.

Jim
 
Hi
To be little more specific.....

IF.... myDate = DATE() .........
myDatePlus1Month = GOMONTH(myDate,1)
myDateMinus1Month = GOMONTH(myDate,-1)
myDate1stDate = myDate - DAY(myDate) + 1
myDateLastDate = GOMONTH(myDate,1) - DAY(myDate)
.... so on
Hope this helps you :)
ramani :-9
(Subramanian.G)
FoxAcc
ramani_g@yahoo.com
LET KNOW IF THIS HELPED. ENOUGH EXPERTS ARE HERE TO HELP YOU OUT! BEST OF LUCK :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top