Meta Stack Exchange is where users like you discuss bugs, features, and support issues that affect the software powering all 158 Stack Exchange communities.

What is meta?
Here's how it works:
  1. Any Stack Exchange user can ask a question
  2. The community provides support, votes on ideas, and reports bugs
  3. Your voice helps shape the way Stack Exchange operates

Is it possible to have DATETIME parametrised queries on the Stack Exchange Data Explorer, e.g:


The output is usually completely unrelated to the input ('2010-01-01' converted to '1905-07-02') - date conversion functions don't seem to be much help either.

share|improve this question
SEDE doesn't actually parameterize queries -- it's merely a string replacement. Adding the :string hint auto-quotes when that process happens. – Jon Seigel Jan 25 '11 at 18:20
up vote 2 down vote accepted

You should be using

DECLARE @MyDate DATETIME = ##MyDate:string##

AFAIK, SQL Server accepts strings for ANY datatype to be implicitly converted.

The snippet works on SEDE.

share|improve this answer

After posting this I also found that using "'2010-01-01'" (including the ' quotes) worked with the example posted in the question.

share|improve this answer

You can also use the following:

Declare @inputDate varchar(8)

Set @InputDate = ##MyDate##
set @MyDate = Convert(datetime, @InputDate)

From Users
Where CreationDate > @MyDate​​​​​​​
And CreationDate < DateAdd(day, 3, @MyDate)

share|improve this answer
This didn't work for me - replacing the SELECT with SELECT @MyDate gave me 2008-01-01 when I entered "2010-01-01" – Justin Jan 25 '11 at 8:59
@Kragen - It needs to be in the format of 20080101 not 2008-01-01 – codingbadger Jan 25 '11 at 9:02
Oh, that also works - a completely different format from what I was expecting though. – Justin Jan 25 '11 at 9:07

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .