Laureta Xhaferraj
Laureta Xhaferraj

Reputation: 63

The conversion of a nvarchar data type to a datetime data type

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.

Upvotes: 0

Views: 1113

Answers (1)

Gordon Linoff
Gordon Linoff

Reputation: 1269583

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.

Upvotes: 0

Related Questions