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

Our new SQL Server Forums are live! Come on over! We've restricted the ability to create new threads on these forums.

SQL Server Forums
Profile | Active Topics | Members | Search | Forum FAQ
Register Now and get your question answered!
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 DateTime error
 Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

Yak Posting Veteran

90 Posts

Posted - 09/01/2013 :  15:27:45  Show Profile  Reply with Quote
DECLARE @datefrom DateTime
SET @datefrom = '30/11/2013 00:00:00'

SELECT [events].datefrom, [events].*
FROM [events]
WHERE [events].live > 0 AND [events].deleted < 1
AND (@datefrom <= datefrom OR @datefrom is null OR @datefrom = '')

WHEN running this in SQL, this flashes a list of the events with the date filter then reports:

The conversion of a char data type to a datetime data type resulted in an out-of-range datetime value.

(852 row(s) affected).

I'm confused, I don't know what is going on?
I got the '30/11/2013 00:00:00' from .net datetime SQL parameter type

Aged Yak Warrior

545 Posts

Posted - 09/01/2013 :  17:07:15  Show Profile  Reply with Quote
SET @datefrom = convert(datetime,'2013-11-30 00:00:00',120)

SET @datefrom = cast('2013-11-30 00:00:00' as datetime)
Go to Top of Page

In (Som, Ni, Yak)

17689 Posts

Posted - 09/01/2013 :  21:59:55  Show Profile  Reply with Quote
best is simply specify the date in ISO format
SET @datefrom = '2013-11-30'

Time is always against us

Go to Top of Page

Flowing Fount of Yak Knowledge

2242 Posts

Posted - 09/02/2013 :  01:06:03  Show Profile  Reply with Quote
Better to use ISO format for DATE..

DECLARE @datefrom DateTime
SET @datefrom = '20131130' -- YYYYMMDD
SELECT @datefrom
what is the datatype of column datefrom ?
If VARCHAR, first convert datefrom to datetime in the WHERE clause

Refer this link:

Edited by - bandi on 09/02/2013 01:06:58
Go to Top of Page
  Previous Topic Topic Next Topic  
 Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.03 seconds. Powered By: Snitz Forums 2000