0
votes

How can I convert date format in SQL Server 2008?

SELECT 
   Dateadd(DAY, (SELECT MaxCheckday
                 FROM tbl_LibryMemberCategory
                 WHERE IsDeleted = 'N'), Getdate()) 

While running the above query I get this error

Msg 242, Level 16, State 3, Line 1
The conversion of a varchar data type to a datetime data type resulted in an out-of-range value.

2
can you edit the question with result of select MaxCheckday from tbl_LibryMemberCategory where IsDeleted='N'and there is no format converstion happening in your query. - Pரதீப்
What is the return data type of MaxCheckDay? - agentpx
MAXCHECKDAY IS RETURN "7 DAYS" VAIUES - krishna
I guess you are doing this convert(varchar,Getdate(),103) in Dateadd - Pரதீப்
MAXCHECKDAY should be numeric 7 only not string "7 DAYS" see corrected query in my answer. - agentpx

2 Answers

0
votes

If am not wrong this is what you are trying to achieve

SELECT CONVERT(VARCHAR(20), Dateadd(Day, MaxCheckday, Getdate()), 103)
FROM   tbl_LibryMemberCategory
WHERE  IsDeleted = 'N' 

Problem in your query is performing Dateadd after the Convertion. Try running the below you will get the same error

SELECT Dateadd(day,1, convert(varchar,Getdate(),103)) 
0
votes

MaxCheckDay should be 7 only, not "7 DAYS".

 SELECT Dateadd(dd,(SELECT MaxCheckday
             FROM   tbl_LibryMemberCategory
             WHERE  IsDeleted = 'N'), Getdate())