devxlogo

DateAdd Function Parameters

DateAdd Function Parameters

Question:
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″)]?

Answer:
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.

See also  Monetize TikTok For Your Business
devxblackblue

About Our Editorial Process

At DevX, we’re dedicated to tech entrepreneurship. Our team closely follows industry shifts, new products, AI breakthroughs, technology trends, and funding announcements. Articles undergo thorough editing to ensure accuracy and clarity, reflecting DevX’s style and supporting entrepreneurs in the tech sphere.

See our full editorial policy.

About Our Journalist