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


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

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
Thanks for your registration, follow us on our social networks to keep up-to-date