Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Problem searching by date

Author  Topic 

richardlaw
Yak Posting Veteran

68 Posts

Posted - 2011-08-21 : 08:52:11
Hi

I'm trying to search based on a date using the following:

"SELECT * FROM tbl_ClassAbsences WHERE ClassAbsence_Date = 30/08/2011 12:00:00 AM ORDER BY ClassAbsence_AbsentTypeID"

But I'm getting errors??? I know the date is right?

Any thoughts

Thanks as always
Rich

Richard Law

sunitabeck
Master Smack Fu Yak Hacker

5155 Posts

Posted - 2011-08-21 : 09:31:39
YOu need single quotes around the date string.

SELECT * FROM tbl_ClassAbsences WHERE ClassAbsence_Date = '30/08/2011 12:00:00 AM' ORDER BY ClassAbsence_AbsentTypeID
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2011-08-21 : 11:43:42
also make sure you pass date formats in iso format (YYYYMMDD) where ever possible to avoid ambiguity. In other case, the system may interpret date wrongly based on what its regional and language settings are.

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

iccube
Starting Member

2 Posts

Posted - 2011-08-22 : 05:21:00
HI

You are right Its regional and language setting

OLAP
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2011-08-29 : 05:00:02
To supposrt what Visakh said, refer this
http://beyondrelational.com/blogs/madhivanan/archive/2010/06/03/understanding-datetime-column-part-ii.aspx

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -