Current location - Plastic Surgery and Aesthetics Network - Plastic surgery and medical aesthetics - Sql server2000, how to add and subtract data of type char?
Sql server2000, how to add and subtract data of type char?
First of all, 20 1702 is not a complete format that can be converted into date even if it is a char type, and it needs at least three sections: year, month and day.

-( 1) Add your char to the complete date format char, and I will add 0 1 after it, so that 20 17020 1 is a convertible format.

Choice? '20 1702'+'0 1'

-(2) Convert to date type and use the cast method.

Choice? cast('20 1702'+'0 1 '? assmalldatetime)

-So this is a time type? Then add and subtract dates and use dateadd.

Choice? dateadd(? Hmm? 1,cast('20 1702'+'0 1 '? assmalldatetime)? )

The first parameter of-dateadd function is unit, year, mm month, day is day, mi minute, ss second.

-The second parameter is the quantity, such as 1, which means adding 1 month.

The third parameter is the time of change.