How to Calculate Date using Date Diff and Date Add Function

this code will show you on how to calculate the difference of  two dates like for example 1
0/10/2010 to 10/01/2010 to find the lapsed day we use a Date Diff function that is 
built in VB6 so the code will look like this:

Label1.Caption = DateDiff("d", #10/1/2010#, #10/10/2010#)

at this code i display the output on a label control did you notice that the Date Diff function i
s there,since i am looking for  day lapsed to 10/01/2010 to 10/10/2010 the output is 9 if you 
are looking for a month just simply change the letter "d" to letter  "m" for a month symbol
and of  course it is not complete if i did  not include for a year,so for the year calculation just
simply change  also the letter on a two double quote(" ") to a "yyyy" and you  got the answer......

for a Month:
DateDiff("m", #10/1/2010#, #10/10/2010#)

 for a Year:
DateDiff("yyyy", #10/1/2010#, #10/10/2010#)

For the Date Add function for example we have add 3 days on the current date so it will
done like this:

this will add 3 days on your current system date 
 DateAdd("d", 3, Now)

this will add 3 months on your current system date
for a Month:
DateAdd("m", 3, Now)

 this will add 3 years on your current system date for a Year:
DateAdd("yyyy", 3, Now)

 Hope this will help to you!!
Happy Coding
These icons link to social bookmarking sites where readers can share and discover new web pages.
  • Digg
  • Sphinn
  • del.icio.us
  • Facebook
  • Mixx
  • Google
  • Furl
  • Reddit
  • Spurl
  • StumbleUpon
  • Technorati

Leave a comment

Copyright @ Codes-47.Blogspot.Com. Powered by Blogger.