How to get Date portion of DateTime field?

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance

From: GaryZ (GaryZ_at_discussions.microsoft.com)
Date: 01/12/05


Date: Wed, 12 Jan 2005 06:13:02 -0800

I'm trying to import an SQLServer table into Visual FoxPro (I'll also post
this in the VFP forum). I need to test the Date portion of a SQL Server
DateTime field against a user-entered Date.

I tried the following:

m_getagsc = SQLPREPARE(gnConnHandle, "SELECT * FROM AgentStateChange "+;
                "WHERE AgentStateChange.ToState > 2"+;
"AND TTOD(AgentStateChange.Time) = ?m_rptdate", "agsc")

m_getagsc = SQLEXEC(gnConnHandle)

After this statement, m_getagsc = -1.

This works without the "AND TTOD(AgentStateChange.Time) = ?m_rptdate".

m_rptdate is a variable containing the user's entered date.
TTOD() is Visual FoxPro's function for returning the Date portion of a
DateTime field. I guess what I need is the SQLServer equivalent.

Thanks,
GaryZ