1

Topic: Append query n - years and days to date

Good afternoon! Help please with request. There is a table. It is necessary to add to column Time1 to  10 years and 10 days, and then to compare to column Time 2. Tried to write request
Select *
from Table 1
Where Time1 between ' 2017-09-17 0:00:00 AM ' and ' 2017-09-17 0:00:00 AM'
and dateadd (year, 10, Time1)> =Time2
But the error - The conversion of a varchar data type to a datatime data type resulted in an out-of-range value is deduced.

2

Re: Append query n - years and days to date

twenty7even wrote:

Good afternoon! Help please with request. There is a table. It is necessary to add to column Time1 to  10 years and 10 days, and then to compare to column Time 2. Tried to write request
Select *
from Table 1
Where Time1 between ' 2017-09-17 0:00:00 AM ' and ' 2017-09-17 0:00:00 AM'
and dateadd (year, 10, Time1)> =Time2
But the error - The conversion of a varchar data type to a datatime data type resulted in an out-of-range value is deduced.

it is visible, on September, 35th it is not pleasant to the server.

3

Re: Append query n - years and days to date

2017-09-35 0:00:00 AM
What is serious?

4

Re: Append query n - years and days to date

V. Liseev, I wrote dates for an example.

5

Re: Append query n - years and days to date

The grandfather, it for an example...

6

Re: Append query n - years and days to date

[V. Liseev] it is passed...
Probably, on September, 35th it is not pleasant to the server. [/quote] In many cases it will not like also 23rd month!
The author is not able to set date unambiguously at all. sad((

7

Re: Append query n - years and days to date

twenty7even;

Select
*
from
Table 1
Where
try_convert (datetime, Time1) is null

that returns?

8

Re: Append query n - years and days to date

wrote:

twenty7even;

Select
*
from
Table 1
Where
try_convert (datetime, Time1) is null

What returns?

This check will depend, most likely, on current adjustments.
What sense in it?
Especially if both day, and month in the field less than thirteen.

9

Re: Append query n - years and days to date

iap;
Sense in that that eyes to see that that leads to an error
Then with it it is possible was specific to understand a context of current adjustments

10

Re: Append query n - years and days to date

The grandfather, can simply show on an example as to a field with date to add n th  the years, what function to use?

11

Re: Append query n - years and days to date

twenty7even;

set dateformat ymd
declare @t table
(id int identity, time1 varchar (50))
insert @t (time1)
values
(' 2017-09-15 '),
(' 2017-09-25 ')
select
time1, dateadd (yy, 10, time1) as time10
from
@t