dcsimg
Login | Register   
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX

By submitting your information, you agree that devx.com may send you DevX offers via email, phone and text message, as well as email offers about other products and services that DevX believes may be of interest to you. DevX will process your information in accordance with the Quinstreet Privacy Policy.


Tip of the Day
Language: Visual Basic
Expertise: Beginner
Jul 23, 1999

WEBINAR:

On-Demand

Application Security Testing: An Integral Part of DevOps


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.

DevX Pro
 
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap
×
We have made updates to our Privacy Policy to reflect the implementation of the General Data Protection Regulation.
Thanks for your registration, follow us on our social networks to keep up-to-date