Msg 241, Level 16, State 1, Line 1
Conversion failed when converting date and/or time from character string.
here' s my query
here' s my query
SELECT
MaxDate,
MinDate,
DATEDIFF(D, MaxDate, MinDate)
FROM (
SELECT
(SELECT MAX(TDate) ) AS MaxDate
,(SELECT MIN(TDate) ) AS MinDate
FROM EDATA
)a
4 Replies
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.

Abhishek JaiswalPosted Aug 29, 2014, 12:13 AM
I was using Simply DATE as datatype , that's why that error was occuring. but when i changed it into DATETIME the same query is working for me as well.
Between thanks for ur kind suggestion.:)
Abhishek JaiswalPosted Aug 29, 2014, 12:12 AM
Cast and convert were not working, I already tried.
Ramesh MaruthiPosted Aug 28, 2014, 10:56 AM
SELECT
MaxDate,
MinDate,
convert(datetime,DATEDIFF(D, MaxDate, MinDate)) as diff
FROM (
SELECT
(SELECT MAX(TDate) ) AS MaxDate
,(SELECT MIN(TDate) ) AS MinDate
FROM EDATA
)a
2 way:
SELECT
MaxDate,
MinDate,
DATEDIFF(D, MaxDate, MinDate) as diff
FROM (
SELECT
(SELECT cast( MAX(TDate) as datetime) ) AS MaxDate
,(SELECT Cast(MIN(TDate) as datetime) ) AS MinDate
FROM EDATA
)a
RahulPosted Aug 28, 2014, 10:53 AM