0
votes

I have a query like below:

select 
  ...
 convert(VARCHAR(10), DATEADD(day,t.DAYNUMBER,t.START_DATE), 103) AS END_DATE
 where END_DATE >=  GETDATE()

It displays the following error:

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

t.DAYNUMBER comes from:

select max([day]) from TOUR_SPECIFIKA 

where day is int. And t.START_DATE is date. I don't know why it shows nvarchar in error.

1
What value are you trying to convert here??marc_s
t.start_date is dateLaureta Xhaferraj
Based on the syntax, you seem to be using SQL Server. You should also tag the question with the version.Gordon Linoff
@marc_s T.START_DATE is date type and daynumber is int. what is going wrong?Laureta Xhaferraj

1 Answers

0
votes

If you have this code:

select ...,
       convert(VARCHAR(10), DATEADD(day, t.DAYNUMBER, t.START_DATE), 103) AS END_DATE
where END_DATE >= GETDATE()

And you are getting that particular error, then either t.START_DATE or t.END_DATE are nvarchar() rather than some date/time data type. One of these columns contains an invalid date.

Note that the reference in the where clause is to a column in one of the tables. It is not a reference to the alias in the SELECT.