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

Date operations in FoxPro 6 1

Status
Not open for further replies.

WaZda

Programmer
Jun 22, 2007
48
GB
Hi foxpro users,
i need an select statement in which which should give me informations on a particular date. i would like to test a date column(date_limit) to see if the month of that date minus 3 month = the system month part of the current date.
Code:
 select * from table where (datepart('m', date()) = datepart('m', Dateadd('m', -3, date_limit))).
i think this should work on an sql server. It gives me errors in foxpro. Can someone please help? The query is to know informations in the database three months from now.
 
The VFP Function to use is GOMONTH():

SELECT * FROM table WHERE date_column = GOMONTH( DATE(), 3 )



----
Andy Kramek
Visual FoxPro MVP
 
hi AndyKr (Programmer),
really don't know how to thank u. u really helped me. the code ROCKSSSSSSSSSSSSSSSSSSSSSSSSSS. Thanks a lot man. Really appreciate it
 
AndyKr (Programmer),
by the way, was my SQL statement correct? if not could you please give me the sql statement version of the above code?
 

WaZda,

Andy's code is an SQL-SELECT statement, and your SQL statement contains functions that don't exist in FoxPro.

Even though I think you need something like this:

Code:
SELECT * FROM table ;
   WHERE MONTH(GOMONTH(DATE(),3))=MONTH(date_limit) AND ;
         YEAR(GOMONTH(DATE(),3))=YEAR(date_limit)
 
thanks a lot Stella740pl (Programmer),
ur code rocks as well.
 
Hi WaZda

Your original code, for SQL Server was:

select * from table where (datepart('m', date()) = datepart('m', Dateadd('m', -3, date_limit))).

But an easier way to do this in SQL Server is to use the DateDiff function rather than DatePart()/DateAdd.

This will select any record where the value of (date_value) is exactly 3 months less than the value of (date_limit):
Code:
SELECT * FROM table 
 WHERE DATEDIFF( m, date_value, date_limit ) = 3

----
Andy Kramek
Visual FoxPro MVP
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top