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

Date problem in SQL Server 2005 and Visual Studio 1

Status
Not open for further replies.

AndyH1

Programmer
Jan 11, 2004
350
GB
I put a question up yesterday about how to specify dates in an SQL Query. I recieved two suggestions, either

WHERE EntryDate > '2008-12-01'

or
WHERE EntryDate > '01/12/2008'

However I'm getting some real problems and wonder if someone can suggest what I'm doing wrong (maybe its some setting). If I use a date format of '2008-12-01' in a view in SQL Server 2005 it runs the query fine in SQL Server 2005 (ie open view), but as soon as I try to run the view in Visual Studio 2005 with a data provider it complains data type resulted in out of range datetime value. However, if I use the date format '01/12/2008' in the view, then SQL Server complains when I try and run the view and gives out the same out of range datetime, but the view runs ok in Visual Studio. I don't think whether either give the right result, but think the one in SQL server does (using 2008-12-01) but the visual studio one doesn't.
 
You should always use so called ISO format. SQL Server has no problems at all with it:
Code:
WHERE EntryDate > '20081201' -- 01 Dec 2008
That format is [YYYYMMDD]

Borislav Borissov
VFP9 SP2, SQL Server 2000/2005.
 
Thanks Borislav, seems visual studio didn't like the dashes, seems to run in both now
Andy
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top