DateAdd Function Parameters

DateAdd Function Parameters

While using the dateadd() function to add the given number to an existing year, it adds the days instead of years if we use the command in the following manner:

If the date is entered in “mm-dd-yy” format,dateadd("yy",5,"07-01-99"), the output will be “07-06-99”.

If we use:dateadd("yyyy",5,"07-01-99"), then the output will be “07-01-04”.

I would like to know why it is adding the days instead of year if we use the first syntax [dateadd (“yy”,5,”07-01-99″)]?

The main reason this doesn’t work the way you expect it to is that “yy” is not an acceptable parameter.

According to Microsoft’s documentation, you can add days to a date with either a single y, d, or w. It looks like the function is assuming that yy = y and is adding days to the date. If you want to add years, use the yyyy parameter you used in the second sample.


Share the Post: