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

Date comparison in Where clause?

Status
Not open for further replies.

thatguy

Programmer
Aug 1, 2001
283
0
0
US
Hey there folks--

I'm trying to build a query during runtime to populate a grid based on a date range. One of the fields in the grid is a DateTime and the date range text box values init to "=date()", so they return date values.

I'm wondering if there's a more efficient way to do date comparisons than this:

Code:
ldstdate = thisform.txtstdate.value
ldenddate = thisform.txtenddate.value

lcsqlst = "SELECT * FROM audit WHERE (ddate >= {^" +;
 ALLTRIM(STR(YEAR(ldstdate))) + "/" + ;
 ALLTRIM(STR(MONTH(ldstdate))) + "/" + ;
 ALLTRIM(STR(DAY(ldstdate))) + ;
 "} AND ddate <= {^" + ;
 ALLTRIM(STR(YEAR(ldenddate))) + "/" + ;
 ALLTRIM(STR(MONTH(ldenddate))) + "/" + ;
 ALLTRIM(STR(DAY(ldenddate))) + ;
 "} ORDER BY ddate DESC INTO CURSOR curgrdaudit"

This works, but I'm wondering if there's an easier way to get a date value into the SQL string for a date-to-date comparison.

Thanks
-- michael~

PS.- Anyone know when the search function is gonna be working again? [sadeyes]
 
Hi michael,

Date values can be compared directly as in

?date1 <= date2

Just convert your datetime value to date using TTOD and you're all set.

Jim
 
Better yet, just use the DATE(nYear, nMonth, nDay) function.

Craig Berntson
MCSD, Visual FoxPro MVP, Author, CrysDev: A Developer's Guide to Integrating Crystal Reports&quot;
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top